Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PILHA SEGMENT PARA STACK 'STACK'
- db 2048 dup(?)
- PILHA ENDS
- DADOS SEGMENT PARA 'DATA'
- ;######################### variaveis programa ##################################
- mynum db 123
- result1 db 5 dup(?)
- result2 db 5 dup(?)
- ;###############################################################################
- DADOS ENDS
- CODIGO SEGMENT PARA 'CODE'
- ASSUME CS:CODIGO, DS:DADOS, SS:PILHA
- INICIO:
- MOV AX, DADOS
- MOV DS, AX
- ;
- ;######################### funcoes programa ####################################
- xor si, si ;si -> 0
- mov cl, 0Ah ;cl -> 10
- mov al, mynum ;al -> 123
- continuar:
- xor ah, ah ;ah -> 0
- div cl ;al:ah -> ax / cl
- ;123 / 10
- ;al = 12
- ;ah = 3
- ;12 / 10
- ;al = 1
- ;ah = 2
- mov result1[si], ah ;result1[si] -> ah
- inc si ;si -> si + 1
- cmp al, 9 ;compare
- jg continuar ;jg(jump if greater) jump if al is greater than 9
- ;if the number we are comparing is less than 10, the first digit will be 0
- ;and we dont want to convert that, so, let's make some changes and jump
- ;if the number is greater than 9, we also use the al value, otherwise
- ;we need to remover. Pay attention
- cmp al, 0 ;compare
- jne saltar ;jump if al is not equal to 0
- dec si ;si -> si - 1
- xor di, di ;di -> 0
- jmp inverter ;jump
- saltar:
- mov result1[si], al ;result1[si] -> al
- xor di, di ;al -> 0
- inverter:
- ;after converting, the text will be inverted. For example, convert 123 and the text will be 321.
- ;so, let's invert again
- mov ah, result1[si] ;al -> result1[si]
- add ah, 30h ;para caracter
- mov result2[di], ah ;result2[di] -> ah
- dec si ;si -> si - 1
- inc di ;di -> di + 1
- cmp si, 0 ;compare
- jge inverter ;jump if si is greater than 0
- mov result2[di], '$';add the end of text
- mov ah, 09h
- lea dx, result2
- int 21h ;print the result
- ;###############################################################################
- FIM:
- MOV AH,4Ch
- INT 21h
- CODIGO ENDS
- END INICIO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement