Assignment 9
Assignment 9
Submitted By-
Group: B1
Name: Md. Rakibul Islam
Id: 18.01.04.072
Section: B
Question No: 01
Question: Write a program that lets the user enter time in seconds, up to 65535,
and outputs the time as hours, minutes, and seconds.
Answer:
;a program that lets the user enter time in seconds, up to 65535, and outputs
;the time as hours, minutes, and seconds
.MODEL SMALL
.STACK 100H
.DATA
MSG1 DB 'Enter the time in seconds up to 65535 = $\'
MSG2 DB 0DH,0AH,'The time in hh:mm:ss format is = $\'
SEPARATOR DB ' : $\'
.CODE
MAIN PROC
MOV AX,@DATA ;initialize DS
MOV DS,AX
HOURS:
CALL OUTDEC ;call the procedure OUTDEC
MINUTES:
CALL OUTDEC ;call the procedure OUTDEC
SECONDS:
CALL OUTDEC ;call the procedure OUTDEC
SKIP_BACKSPACE:
MOV AH,2 ;set output function
MOV DL,20H ;set DL=' \'
INT 21H ;print a character
READ:
XOR BX,BX ;clear BX
XOR CX,CX ;clear CX
XOR DX,DX ;clear DX
MINUS:
MOV CH,1 ;set CH=1
INC CL ;set CL=CL+1
JMP INPUT ;jump to label INPUT
PLUS:
MOV CH,2 ;set CH=2
INC CL ;set CL=CL+1
INPUT:
MOV AH,1 ;set input function
INT 21H ;read a character
SKIP_INPUT:
JUMP_TO_END_INPUT:
CHECK_REMOVE_MINUS:
CHECK_REMOVE_PLUS:
CMP CL,1 ;compare CL with 1
JE REMOVE_PLUS_MINUS ;jump to label REMOVE_PLUS_MINUS if CL=1
JMP MOVE_BACK ;jump to label MOVE_BACK
REMOVE_PLUS_MINUS:
MOV AH,2 ;set output function
MOV DL,20H ;set DL=\' \'
INT 21H ;print a character
MOVE_BACK:
NOT_BACKSPACE:
INC CL ;set CL=CL+1
CMP CL,5
JG ERROR
JMP INPUT ;jump to label @INPUT
ERROR:
CLEAR:
MOV DL,8H ;set DL=8H
INT 21H ;print a character
MOV DL,20H ;set DL=\' \'
INT 21H ;print a character
END_INPUT:
EXIT:
START:
XOR CX,CX ;clear CX
MOV BX,10 ;set BX=10
OUTPUT:
XOR DX,DX ;clear DX
DIV BX ;divide AX by BX
PUSH DX ;push DX onto the STACK
INC CX ;increment CX
OR AX, AX ;take OR of Ax with AX
JNE OUTPUT ;jump to label OUTPUT if ZF=0
DISPLAY:
POP DX ;pop a value from STACK to DX
OR DL, 30H ;convert decimal to ascii code
INT 21H ;print a character
LOOP DISPLAY ;jump to label @DISPLAY if CX!=0
.MODEL SMALL
.STACK 100H
.DATA
MSG1 DB 'Enter the value of M = $'
MSG2 DB 0DH,0AH,'Enter the value of N = $'
MSG3 DB 0DH,0AH,'The GCD of M and N is = $'
.CODE
MAIN PROC
MOV AX,@DATA ;initialize DS
MOV DS,AX
REPEAT:
XOR DX,DX ;clear DX
DIV BX ;set AX=DX:AX\BX , AX=DX:AX%BX
END_LOOP:
SKIP_BACKSPACE:
MOV AH,2 ;set output function
MOV DL,20H ;set DL=' '
INT 21H ;print a character
READ:
XOR BX,BX ;clear BX
XOR CX,CX ;clear CX
XOR DX,DX ;clear DX
MINUS:
MOV CH,1 ;set CH=1
INC CL ;set CL=CL+1
JMP INPUT ;jump to label INPUT
PLUS:
MOV CH,2 ;set CH=2
INC CL ;set CL=CL+1
INPUT:
MOV AH,1 ;set input function
INT 21H ;read a character
SKIP_INPUT:
CHECK_REMOVE_MINUS:
CHECK_REMOVE_PLUS:
REMOVE_PLUS_MINUS:
MOV AH,2 ;set output function
MOV DL,20H ;set DL=' '
INT 21H ;print a character
MOVE_BACK:
NOT_BACKSPACE:
ERROR:
CLEAR:
MOV DL,8H ;set DL=8H
INT 21H ;print a character
END_INPUT:
EXIT:
START:
OUTPUT:
XOR DX,DX ;clear DX
DIV BX ;divide AX by BX
PUSH DX ;push DX onto the STACK
INC CX ;increment CX
OR AX, AX ;take OR of Ax with AX
JNE OUTPUT ;jump to label OUTPUT if ZF=0
DISPLAY:
POP DX ;pop a value from STACK to DX
OR DL,30H ;convert decimal to ascii code
INT 21H ;print a character
LOOP DISPLAY ;jump to label DISPLAY if CX!=0
END MAIN