Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Write a program that prints to the screen the decimal value of a positive integer number (0 ÷ 2^(16)-1), stored into an appropriate variable
- ;IMPLEMENTATION
- ;Use an algorithm in two phases:
- ;-Decomposition of binary number into its digits by successive division for 10, saving the remainders and repeating operation on quotient until this is different from 0
- ;-Display of digits so obtained in reverse order than that initial, using the stack
- ;-N.B.: digits must be converted into ASCII characters before printing
- ;I declare that about division I do it by
- ;a number in 32bit (DD) because when
- ;I do PUSH or POP, it wants needs
- ;registers in 16 bit, not in 8 bit, and so
- ;is easier
- .MODEL small
- .STACK
- .DATA
- VAR DD 4325 ;numero da stampare
- divisore DW 10 ;divisore
- .CODE
- .START
- MOV AX,WORD PTR VAR
- MOV DX,WORD PTR VAR+2
- ciclo: DIV divisore ;This cycle converts my number
- ADD DX,'0' ;I remember that in DIV DX stores the remainder.
- ;I sum +'0' so in DX I have the position of
- ;stored number but in ASCII code
- PUSH DX ;I store DX into STACK
- MOV DX,0
- INC BX ;BX counts the digits (After I will need of this for printing cycle)
- CMP AX,0 ;If quotient is 0, then go out from cycle
- JNZ ciclo
- MOV AH,2 ;OUTPUT
- stampa: POP DX ;In DX (so in DL) will be stored ASCII code of digits that I stored into stack
- INT 21h
- DEC BX
- JNZ stampa
- .EXIT
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement