Advertisement
Kunta

8086 ASM exercise

Feb 3rd, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. name "sum maxi"
  2.  
  3.  
  4. name "sum maxi"
  5.      
  6.      
  7. Data     SEGMENT
  8.      N  DB 4 DUP(?)
  9.      SOMME  DW 3 DUP(?)
  10.      MAXI  DW 3 DUP(?)
  11.      VALSOM DB 3 DUP(?)
  12. Data     ENDS
  13.  
  14. Code     SEGMENT
  15. Start:
  16.          MOV MAXI,100                  ;initialising the maximum
  17.          MOV AX,0
  18.          MOV BX,0
  19.          MOV CX,0      
  20. Loop:    INC BX                ;increasing the integers counter
  21.      MOV SOMME,AX               ;copying total to the SUM variable
  22.          ADD AX,BX             ;adding this integer to the total
  23.          CMP AX,MAXI               ;testing that the total amount is less or equal than maxi
  24.          JLE Loop              ;if yes relooping
  25.          DEC BX                ;if no decrease the numbers counter
  26.          MOV AX,BX             ;move bx value to ax
  27.          MOV N,AL                  ;saving the value to N
  28.          MOV BX,10             ;preparing bx to divide
  29.          DIV BX                    ;converting to decimal through DX
  30.          ADD AX,48                 ;converting first digit to ascii
  31.          ADD DX,48                 ;converting second digit to ascii
  32.          MOV AH,AL                 ;moving first digit to AH
  33.          MOV AL,DL                 ;moving second digit to AL
  34.      MOV BX,offset N
  35.          MOV [BX],AH
  36.      MOV Byte ptr[BX+1],AL
  37.      MOV Byte ptr[BX+2],20h
  38.      MOV Byte ptr[BX+3],'$'
  39.      MOV AX,SOMME
  40.      MOV DX,0
  41.          MOV BX,10              ;preparing bx to divide
  42.          DIV BX                     ;converting to decimal through DX
  43.          ADD AX,48                  ;converting first digit to ascii
  44.          ADD DX,48                  ;converting second digit to ascii
  45.          MOV AH,AL                  ;moving first digit to AH
  46.          MOV AL,DL                  ;moving second digit to AL
  47.      MOV BX,offset VALSOM
  48.          MOV [BX],AH
  49.      MOV Byte ptr[BX+1],AL
  50.      MOV Byte ptr[BX+2],'$'
  51.          MOV DX,offset N
  52.          MOV AH,9
  53.          INT 21h
  54.          MOV DX,offset VALSOM
  55.          MOV AH,9
  56.          INT 21h
  57.          MOV AX,4C00h
  58.          INT 21h
  59. Code     ENDS
  60.          END  Start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement