-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPROGRAM TO GIVE POWER.asm
More file actions
89 lines (74 loc) · 1.79 KB
/
PROGRAM TO GIVE POWER.asm
File metadata and controls
89 lines (74 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
;PROGRAM TO GIVE THE POWER OF CERTAIN NUMBER
.model SMALL
.STACK 100H
.DATA
MSG DB 'PLEASE ENTER A NUMBER :$'
MSG1 DB 0AH,0DH,'ENTER POWER :$'
NUM DB ?
POW DB ?
RESULT DW 1
MSG2 DB 0AH,0DH,'THE RESULT IS :$'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
;PRINT A MSG
LEA DX, MSG
MOV AH, 09H
INT 21H
;INPUT CHARACTER FOR NUMBER
MOV AH, 01H
INT 21H
MOV NUM, AL
;PRINTING MSG1
LEA DX, MSG1
MOV AH, 09H
INT 21H
;INPUT POWER
MOV AH, 01H
INT 21H
MOV POW,AL
;STORING THE VALUES OF POWER AND NUMBER FOR LOOP PREPERATION
LEA SI, NUM
MOV CL, POW
;NOW USING LOOP
POWER_LOOP:
MOV AL, [SI]
;CODE FOR MULTIPLY ITSLF SO THAT IT COULD FIT IN AX
MOV AH, 0
MUL AL ;NUM=*NUM IN (C/C++)
MOV RESULT, AX
MOV [SI], AL ;RETURNING NUM VALUE TO AL REGISTER(AX LOWER)
DEC CL
JNZ POWER_LOOP
;FOR PRINTING MSG2
LEA DX, MSG2
MOV AH, 09H
INT 21H
MOV RESULT, AX
CALL PRINT_DECIMAL
;TERMINATE END FUNCTION
MOV AH, 4CH
INT 21H
MAIN ENDP
;PROCEDER TO PRINT IT INTO DECIMAL BECAUSE IT WAS STORED IN BINARY IN AX
PRINT_DECIMAL PROC
; Convert AX to a string and print it
mov bx, 10 ; Divisor for decimal conversion
mov cx, 0 ; Initialize digit count
convert_loop:
xor dx, dx ; Clear DX
div bx ; Divide AX by 10, QUOTEINT IS IN AX, remainder in DX
push dx ; PUSH THE remainder (digit) onto STACK
inc cx ; Increment digit count
test ax, ax ; Check if quotient is zero
jnz convert_loop
print_loop:
pop dx ; Pop digit from stack
add dl, '0' ; Convert digit to ASCII
mov ah, 02h
int 21h ; Print digit
loop print_loop
ret
print_decimal endp
end main