Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

convert inputted negative values to 2's comppliment

this is a part of my calculator code.This code will convert the input values to ASCII value.My problem is when i input negative values, it will not result to desired output.I want to modify this code if ever the input values is negative.I don't know how to modify this program in order for it to convert negative values to 2's compliment.can u help me?

[code]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[/code]
Sign In or Register to comment.