Advertisement
Guest User

Untitled

a guest
Mar 31st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;
  2. ; hw1.asm
  3. ;
  4.     .MODEL SMALL
  5.     .STACK 100h
  6.     .DATA
  7. GetHeight DB 'Enter Height in feet inches, (e.g: 6 2):',13,10,'$'
  8. ResultStr DB 13,10,'X Feet X Inch = XXX cm',13,10,'$'
  9.  
  10. Ten DW 10
  11.  
  12. feet DB ?
  13. inches DB ?
  14. result DW ?
  15.  
  16.      .CODE
  17. ProgStart:
  18.      MOV AX,@DATA             ; DS can be written to only through a register
  19.      MOV DS,AX                ; Set DS to point to data segment
  20.      
  21.      ;print GetHeight
  22.      MOV AH,9
  23.      MOV DX,OFFSET GetHeight
  24.      INT 21h
  25.      
  26.      ;Get feet
  27.      MOV AH,1
  28.      INT 21h
  29.      MOV ResultStr[2],AL
  30.      SUB AL,'0'
  31.      MOV feet,AL
  32.      
  33.      ;ignore space
  34.      INT 21h
  35.      
  36.      ;Get inches
  37.      INT 21h
  38.      MOV ResultStr[9],AL
  39.      SUB AL,'0'
  40.      MOV inches,AL
  41.      
  42.      ;multiple feet by 3048
  43.      MOV AX,3048
  44.      MOV BL,feet
  45.      MOV BH,0
  46.      MUL BX
  47.      MOV result,AX
  48.      
  49.      ;divide result of feet*3048 by 100
  50.      MOV BL,100
  51.      DIV BL
  52.      MOV AH,0
  53.      MOV result,AX
  54.      
  55.      ;multiple inches by 254
  56.      MOV AX,254
  57.      MOV BL,inches
  58.      MOV BH,0
  59.      MUL BX
  60.      
  61.      ;divide result of inches*254 by 100
  62.      MOV BL,100
  63.      DIV BL
  64.      MOV AH,0
  65.      ADD result,AX
  66.      
  67.      ;put result in AX
  68.      MOV AX,result
  69.      
  70.      
  71.      ;now we convert the result to ascii again, char by char, and put in ResultStr
  72.      MOV DX,0
  73.      DIV Ten
  74.      ADD DL,'0'
  75.      MOV ResultStr[20],DL
  76.      ;
  77.      MOV DX,0
  78.      DIV Ten
  79.      ADD DL,'0'
  80.      MOV ResultStr[19],DL
  81.      ;
  82.      MOV DX,0
  83.      DIV Ten
  84.      ADD DL,'0'
  85.      MOV ResultStr[18],DL
  86.      
  87.      ;print ResultStr
  88.      MOV AH,9
  89.      MOV DX,OFFSET ResultStr
  90.      INT 21h
  91.          
  92. EndProgram:
  93.      MOV AH,4Ch               ; Set terminate option for int 21h
  94.      INT 21h                  ; Return to DOS (terminate program)
  95.     END ProgStart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement