Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;
- ; hw1.asm
- ;
- .MODEL SMALL
- .STACK 100h
- .DATA
- GetHeight DB 'Enter Height in feet inches, (e.g: 6 2):',13,10,'$'
- ResultStr DB 13,10,'X Feet X Inch = XXX cm',13,10,'$'
- Ten DW 10
- feet DB ?
- inches DB ?
- result DW ?
- .CODE
- ProgStart:
- MOV AX,@DATA ; DS can be written to only through a register
- MOV DS,AX ; Set DS to point to data segment
- ;print GetHeight
- MOV AH,9
- MOV DX,OFFSET GetHeight
- INT 21h
- ;Get feet
- MOV AH,1
- INT 21h
- MOV ResultStr[2],AL
- SUB AL,'0'
- MOV feet,AL
- ;ignore space
- INT 21h
- ;Get inches
- INT 21h
- MOV ResultStr[9],AL
- SUB AL,'0'
- MOV inches,AL
- ;multiple feet by 3048
- MOV AX,3048
- MOV BL,feet
- MOV BH,0
- MUL BX
- MOV result,AX
- ;divide result of feet*3048 by 100
- MOV BL,100
- DIV BL
- MOV AH,0
- MOV result,AX
- ;multiple inches by 254
- MOV AX,254
- MOV BL,inches
- MOV BH,0
- MUL BX
- ;divide result of inches*254 by 100
- MOV BL,100
- DIV BL
- MOV AH,0
- ADD result,AX
- ;put result in AX
- MOV AX,result
- ;now we convert the result to ascii again, char by char, and put in ResultStr
- MOV DX,0
- DIV Ten
- ADD DL,'0'
- MOV ResultStr[20],DL
- ;
- MOV DX,0
- DIV Ten
- ADD DL,'0'
- MOV ResultStr[19],DL
- ;
- MOV DX,0
- DIV Ten
- ADD DL,'0'
- MOV ResultStr[18],DL
- ;print ResultStr
- MOV AH,9
- MOV DX,OFFSET ResultStr
- INT 21h
- EndProgram:
- MOV AH,4Ch ; Set terminate option for int 21h
- INT 21h ; Return to DOS (terminate program)
- END ProgStart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement