Advertisement
obernardovieira

Integer to Character [Intel 8086]

May 22nd, 2015
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PILHA   SEGMENT PARA STACK 'STACK'
  2.     db 2048 dup(?)
  3. PILHA   ENDS
  4.  
  5. DADOS   SEGMENT PARA 'DATA'
  6. ;######################### variaveis programa ##################################
  7.  
  8.  
  9.  
  10.     mynum   db  123
  11.  
  12.     result1 db  5 dup(?)
  13.     result2 db  5 dup(?)
  14.  
  15.  
  16.  
  17. ;###############################################################################
  18. DADOS   ENDS
  19.  
  20. CODIGO  SEGMENT PARA 'CODE'
  21.     ASSUME CS:CODIGO, DS:DADOS, SS:PILHA
  22.  
  23. INICIO:
  24.     MOV AX, DADOS
  25.     MOV DS, AX
  26. ;
  27.  
  28. ;######################### funcoes programa ####################################
  29.  
  30.  
  31.  
  32.     xor si, si      ;si -> 0
  33.     mov cl, 0Ah     ;cl -> 10
  34.     mov al, mynum   ;al -> 123
  35. continuar:
  36.     xor ah, ah      ;ah -> 0
  37.     div cl      ;al:ah -> ax / cl
  38.     ;123 / 10
  39.     ;al = 12
  40.     ;ah = 3
  41.  
  42.     ;12 / 10
  43.     ;al = 1
  44.     ;ah = 2
  45.     mov result1[si], ah ;result1[si] -> ah
  46.  
  47.  
  48.     inc si      ;si -> si + 1
  49.  
  50.     cmp al, 9       ;compare
  51.     jg continuar    ;jg(jump if greater) jump if al is greater than 9
  52.  
  53.     ;if the number we are comparing is less than 10, the first digit will be 0
  54.     ;and we dont want to convert that, so, let's make some changes and jump
  55.     ;if the number is greater than 9, we also use the al value, otherwise
  56.     ;we need to remover. Pay attention
  57.     cmp al, 0       ;compare
  58.     jne saltar      ;jump if al is not equal to 0
  59.     dec si      ;si -> si - 1
  60.     xor di, di      ;di -> 0
  61.     jmp inverter    ;jump
  62. saltar:
  63.     mov result1[si], al ;result1[si] -> al
  64.     xor di, di      ;al -> 0
  65. inverter:
  66.     ;after converting, the text will be inverted. For example, convert 123 and the text will be 321.
  67.     ;so, let's invert again
  68.     mov ah, result1[si] ;al -> result1[si]
  69.     add ah, 30h     ;para caracter
  70.     mov result2[di], ah ;result2[di] -> ah
  71.     dec si      ;si -> si - 1
  72.     inc di      ;di -> di + 1
  73.     cmp si, 0       ;compare
  74.     jge inverter    ;jump if si is greater than 0
  75.  
  76.     mov result2[di], '$';add the end of text
  77.     mov ah, 09h
  78.     lea dx, result2
  79.     int 21h     ;print the result
  80.  
  81.  
  82.  
  83. ;###############################################################################
  84.  
  85. FIM:
  86.     MOV AH,4Ch
  87.     INT 21h
  88.  
  89. CODIGO  ENDS
  90. END INICIO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement