我正在尝试制作一个用负数执行算术运算的计算器。此处的此代码用于将输入的数字转换为 ASCII 值。如果输入为负数,我想修改此程序以执行 2 的补码转换,它应该会产生所需的输出。
目前这是我的计算器的流程:
-1+2=66675(应该是1)
-1-1=656745(应该是-2)
-1*-1=66757(应该是1)
有人建议我应该修改这部分代码以执行我想要的。我已经尽力了,但它不起作用。你能帮我做这个吗?哦,顺便说一句,我真的是组装新手..
CONVERT_ASSCII PROC NEAR
MOV AH , BYTE PTR RESULT ;MOVE FIRST TWO BYTE OF RESULT TO AX
MOV AL , BYTE PTR RESULT + 1
;AT FIRST CHECK IF AX IS POSITIVE OR NEGETIVE
TEST EAX , 8000H ;CHECK THE LAST BIT . IF THATS 1 THEN AX IS NEG , OTHERWISE THATS POSITIVE
MOV EDI , 0 ;AT FIRST SET OUR FLAG TO ZERO
JZ EAX_POSITIVE ;AX IS POSITIVE
NEG EAX ;CALCULATE NEGETIVE OF AX
MOV EDI , 1 ;DI INDICATES THAT AX IS NEG
EAX_POSITIVE :
MOV ECX , 10
LEA ESI , ASSCII_NUM
ADD ESI , 29 ;MOVE TO THE LAST SPACE
MOV EBP , 0 ;THIS IS THE COUNTER OF CHARS
ASSCII_LOOP : MOV EDX , 0
DIV ECX
OR DL , 30H ;MAKE REMINDER ASSCII
MOV [ESI] , DL ;PUT ASSCII IN ASSCII_NUM
DEC ESI
INC EBP ;ADD ONE TO THE CHAR'S COUNTER
CMP EAX , 0 ;IF AX > 0 GOTO
JA ASSCII_LOOP ;ASSCII_LOOP
CMP EDI , 0 ;CHECK IF THAT WAS A NEGETIVE NUMBER
JZ REST ;IF THATS NOT NEGETIVE GOTO REST
MOV DL , '-'
MOV [ESI] , DL ;ADD A MINES SIGN TO THE STRING
DEC ESI
INC EBP
REST :
LEA EDI , ASSCII_NUM
;MOVE THE ASSCII CODE TO IT'S RIGHT PLCAE IN ASSCII_NUM
ORDER_ASSCII : INC ESI
MOV AL , BYTE PTR [ESI]
MOV BYTE PTR [EDI] , AL
INC EDI
DEC EBP
CMP EBP , 0
JA ORDER_ASSCII
MOV CL , '$'
MOV BYTE PTR [EDI] , CL ;AT LAST PUT A DOLLOR SIGN AT THE END OF ASSCII_NUM
RET
CONVERT_ASSCII ENDP