Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

.

8086
.model small
.stack 1000h

; Data segment
.data
msg1 db "enter to what power: $"
msg2 db "power answer is: $"
msg3 db "enter number: $"
var1 dw 0
var2 db 0

; Code segment
.code
; Set up data segment
mov ax, @data
mov ds, ax

; Display "enter to what power:" message


mov ah, 09h
lea dx, msg1
int 21h

; Read the power input


mov ah, 01h
int 21h
sub al, '0'
mov cl, al

; Display "enter number:" message


mov ah, 09h
lea dx, msg3
int 21h

; Read the number input


mov ah, 01h
int 21h
sub al, '0'
mov bl, al

; Initialize registers for multiplication


mov bh, 0
mov ah, 0
mov ch, 0
dec cx

; Perform multiplication to calculate power


labela:
mul bx
dec cx
cmp cx, 0
jne labela
mov var1, ax

; Display the result


mov ah, 02h
mov dl, 10
int 21h
mov ax, var1
call PRINT ; Call the PRINT procedure

; Exit the program


mov ax, 4c00h
int 21h

; PRINT procedure
PRINT PROC
; Initialize count
mov cx, 0
mov dx, 0

; Loop to extract digits and print


label1:
; If ax is zero
cmp ax, 0
je print1

; Initialize bx to 10
mov bx, 10

; Extract the last digit


div bx

; Push the digit onto the stack


push dx

; Increment the count


inc cx

; Set dx to 0
xor dx, dx
jmp label1

print1:
; Check if count is greater than zero
cmp cx, 0
je exit

; Pop the top of the stack


pop dx

; Add 48 to represent the ASCII value of digits


add dx, 48

; Interrupt to print a character


mov ah, 02h
int 21h

; Decrease the count


dec cx
jmp print1

exit:
ret
PRINT ENDP
end

You might also like