Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dec2String      PROC        NEAR
  2.                 PUBLIC      Dec2String
  3.  
  4. Dec2StringInit:                         ;Initialize function.
  5.     PUSH    AX                      ;Push arguments on the stack.
  6.     PUSH    SI
  7.     MOV     CX, MAX_PWR10               ;Initialize CX as maximal power of 10.
  8.    
  9.     CMP     AX, 0                   ;Check for sign
  10.     JG      Positive
  11.     JZ      Dec2StringLoop              ;If zero, jump to loop directly.
  12.     ;JL     Negative
  13.  
  14. Negative:
  15.     MOV     BYTE PTR [SI], '-'          ;If negative, start with a minus sign.
  16.     NEG     AX
  17.     INC     SI
  18.     JMP     Dec2StringLoop              ;Enter the main loop.
  19.    
  20. Positive:
  21.     MOV     BYTE PTR [SI], '+'          ;If positive, start with a plus sign.
  22.     INC     SI
  23.     ;JMP        Dec2StringLoop              ;Enter the main loop.
  24.    
  25. Dec2StringLoop:
  26.     CMP     CX, 0                   ;Loop while pwr10 > 0
  27.     JZ      EndLoop
  28.     ;JG     LoopBody
  29.    
  30. LoopBody:
  31.     DIV     CX                  ;AX <- quotient, DX <- reminder.
  32.     ADD     AX, ASCII_OFFSET            ;Translate the quotient to ASCII.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement