所以我对汇编语言还很陌生。我的任务是编写一个80x86汇编语言程序(masm)来计算和显示硬币的总价值,以美元和美分计算。
输入:该程序读取用户的硬币数量(便士,镍币,硬币和四分之一)。
输出:该程序显示总金额和美分,以及三行信息的硬币数量。
我可能不会使用任何除法指令。数据部分必须包含四个标签,每个标签用于提示输入硬币类型的字符串
我的代码会找到硬币数量和总价值,我不知道如何输出到多行。感谢帮助或指导。到目前为止,这是我的代码。
.DATA ;reserve storage for data
pennies DWORD ?
nickels DWORD ?
dimes DWORD ?
quarters DWORD ?
prompt1 BYTE "How many pennies do you have?", 0
prompt2 BYTE "How many nickels do you have?", 0
prompt3 BYTE "How many dimes do you have?", 0
prompt4 BYTE "How many quarters do you have?", 0
asciiIn BYTE 15 DUP (?)
resultLbl BYTE "Coin Information", 0
resultText BYTE
.CODE ;start of main program
_MainProc PROC
;read ascii input for pennies, convert to 2's comp, and
input prompt1, asciiIn, 15
atod asciiIn
mov pennies, eax
;read ascii input for nickels, convert to 2's comp, and
input prompt2, asciiIn, 15
atod asciiIn
mov nickels, eax
;read ascii input for dimes, convert to 2's comp, and st
input prompt3, asciiIn, 15
atod asciiIn
mov dimes, eax
;read ascii input for quarters, convert to 2's comp, and
input prompt4, asciiIn, 15
atod asciiIn
mov quarters, eax
;
mov eax, pennies
mov numCoins, eax
mov pennies, eax
mov total, eax
;
mov eax, nickels
add numCoins, eax
mul nickel
add total, eax
;
mov eax, dimes
add numCoins, eax
mul dime
add total, eax
;
mov eax, quarters
add numCoins, eax
mul quarter
add total, eax
dtoa resultText, total
output resultLbl, resultText
mov eax, 0
ret
_MainProc ENDP
END
以下是包含的io宏的代码。
output MACRO outLbl, outStr ; display label and string
pushad ; save general registers
cld ; clear DF
lea eax,outStr ; string address
push eax ; string parameter on stack
lea eax,outLbl ; label address
push eax ; string parameter on stack
call _showOutput ; showOutput(outLbl, outStr)
add esp, 8 ; remove parameters
popad ; restore general registers
ENDM