-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Power.asm #4
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the power.asm is wrong
.MODEL SMALL
.DATA
BASE DW ?
POW DB ?
NL1 DB 0AH,0DH,'ENTER BASE: ','$'
NL2 DB 0AH,0DH,'ENTER POWER: ','$'
RESULT DB 6 DUP('$')
.CODE
MAIN PROC
ENTER_BASE:
LEA DX, NL1 ; Display prompt
MOV AH, 09H
INT 21H
ENTER_POWER:
LEA DX, NL2 ; Display prompt
MOV AH, 09H
INT 21H
READ_NUMBER:
XOR AX, AX ; Clear AX
MOV CX, 10 ; Multiplier
READ_LOOP:
MOV AH, 01H ; Read a character
INT 21H
DONE_READ:
RET
POWER PROC
MOV CX, POW ; Move power to CX
MOV DX, 0 ; Clear DX (result)
MOV AX, 1 ; Set AX to 1 (base case)
POWER_LOOP:
TEST CX, 1 ; Check if power is odd
JZ EVEN_POWER ; If not odd, skip
EVEN_POWER:
SHR CX, 1 ; Divide power by 2
JZ POWER_DONE ; If power is zero, finish
POWER_DONE:
MOV AX, DX ; Move result to AX
RET
POWER ENDP
MAIN ENDP
END MAIN
The text was updated successfully, but these errors were encountered: