我已經編寫了一半的程序。問題是我不知道如何編碼數學運算部分是提高m
的功率爲n (m^n)
。那麼,作爲初學者的任何建議?彙編程序(TASM)計算提升m到n的功率(m^n)
.MODEL SMALL
.DATA
greet db 13,10, "Welcome to Simple Calculator: Raise m to the power n. $"
msg1 db 13,10, 0AH,0DH,"Please enter integer (m:-99 to 99): $"
m db 3,4 dup(?)
msg2 db 10,13, 0AH,0DH,"Please enter power (n:1 to 9): $"
n db 3,4 dup(?)
total db 10,13, "Answer: $"
.CODE
START:
mov ax, seg greet
mov ds, ax
mov dx, offset greet
mov ah, 09h ;Display message
int 21h
mov ax, seg msg1
mov ds, ax
mov dx, offset msg1
mov ah, 09h
int 21h ;Print a message
mov ah, 0ah
mov dx, offset m
int 21h ;Get 'm' value
n_POWER:
mov ax, seg msg2
mov ds, ax
mov dx, offset msg2
mov ah, 09h
int 21h ;Print a message
mov ah, 0ah
mov dx, offset n ;Get 'n' value
int 21h
mov ax, m
mov n, ax
mul ax, n
mov total, n
finish:
mov ah, 09h ;Display message
int 21h
mov ax,4c00h ;Return control to DOS
int 21h
end start
另外,我如何從用戶(例如,-99
)獲得的負輸入?
我需要使用「JMP」命令嗎? – user2264387 2013-04-10 04:08:32