; ICT170 12-HOUR CLOCK ASSIGN 2 .model small .stack 100H .DATA S DB ? ; seconds M DB ? ; minutes H DB ? ; hours MSG1 DB "Input Second Start (0-9): $" MSG2 DB "Input Minute Start (0-9): $" MSG3 DB "Input Hour Start (0-9): $" DIG1 DB ? DIG2 DB ? B1 DB ? .CODE MAIN PROC ; Initializing data MOV AX, @DATA MOV DS, AX _Counter: MOV CX, 43200 ; for 12-hour clock loop, since clock increments by 1 "second", 43200 seconds = 12 hours _UserInputs: ; proc for inputting starting second, minute, hour MOV AH, 9 ; sets AH value for DOS interrupt string display LEA DX, MSG1 ; MSG1 display, asks user for value of SECOND INT 21H MOV AH, 1 ; sets AH value for DOS interrupt character input, SECOND value INT 21H ; SECOND stored in AL SUB AL, 30H ; ASCII to DECIMAL conversion MOV S, AL ; User defines SECOND CALL _NewLine ; CALLS new line proc, creates new line MOV AH, 9 ; sets AH value for DOS interrupt string display LEA DX, MSG2 ; MSG2 display, asks user for value of MINUTES INT 21H MOV AH, 1 ; sets AH value for DOS interrupt character input, MINUTE value INT 21H ; MINUTE stored in AL SUB AL, 30H ; ASCII to DECIMAL conversion MOV M, AL ; User defines MINUTE CALL _NewLine ; CALLS new line proc, creates new line MOV AH, 9 ; sets AH value for DOS interrupt string display LEA DX, MSG3 ; MSG2 display, asks user for value of HOUR INT 21H MOV AH, 1 ; sets AH value for DOS interrupt character input, HOUR value INT 21H ; MINUTE stored in AL SUB AL, 30H ; ASCII to DECIMAL conversion MOV H, AL ; User defines MINUTE CALL _NewLine ; CALLS new line proc, creates new line JMP _Clock _NewLine: ; NewLine procedure MOV DL, 10 ; moves the ASCII value of 'enter' into DL MOV AH, 2 ; INT 21H RET ; returns to caller _TwoDigits: XOR AH, AH MOV B1, 10 DIV B1 MOV DIG1, AL MOV DIG2, AH MOV DL, DIG1 ADD DL, 30H MOV AH, 02H INT 21H MOV DL, DIG2 ADD DL, 30H INT 21H MOV DL, 10 MOV AH, 2 INT 21 RET _Clock: INC S ; One SECOND MOV AL, S ; Places SECOND inside AL XOR AH, AH ; AH is cleared MOV B1, 60 DIV B1 MOV S, AH CMP AL, 1 JNZ _skip INC M _skip: MOV AL, M XOR AH, AH DIV B1 MOV M, AH CMP AL, 1 JNZ _skip1 INC H _skip1: MOV AL, H CMP AL, 12 JNZ _display MOV AL, 0 MOV H, AL _display: MOV AL, H CALL _TwoDigits MOV AH, 2 MOV DL, ':' INT 21H MOV AL, M CALL _TwoDigits MOV AH, 2 MOV DL, ':' INT 21H MOV AL, S CALL _TwoDigits CALL _NewLine LOOP _CLock ; VICTORYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY MOV AH, 4CH INT 21H MAIN ENDP END MAIN
Write, Run & Share Assembly code online using OneCompiler's Assembly online compiler for free. It's one of the robust, feature-rich online compilers for Assembly language. Getting started with the OneCompiler's Assembly compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Assembly
and start coding.
Assembly language(asm) is a low-level programming language, where the language instructions will be more similar to machine code instructions.
Every assembler may have it's own assembly language designed for a specific computers or an operating system.
Assembly language requires less execution time and memory. It is more helful for direct hardware manipulation, real-time critical applications. It is used in device drivers, low-level embedded systems etc.
Assembly language usually consists of three sections,
Data section
To initialize variables and constants, buffer size these values doesn't change at runtime.
bss section
To declare variables
text section
_start
specifies the starting of this section where the actually code is written.
There are various define directives to allocate space for variables for both initialized and uninitialized data.
variable-name define-directive initial-value
Define Directive | Description | Allocated Space |
---|---|---|
DB | Define Byte | 1 byte |
DW | Define Word | 2 bytes |
DD | Define Doubleword | 4 bytes |
DQ | Define Quadword | 8 bytes |
DT | Define Ten Bytes | 10 bytes |
Define Directive | Description |
---|---|
RESB | Reserve a Byte |
RESW | Reserve a Word |
RESD | Reserve a Doubleword |
RESQ | Reserve a Quadword |
REST | Reserve a Ten Bytes |
Constants can be defined using
CONSTANT_NAME EQU regular-exp or value
%assign constant_name value
%define constant_name value
Loops are used to iterate a set of statements for a specific number of times.
mov ECX,n
L1:
;<loop body>
loop L1
where n specifies the no of times loops should iterate.
Procedure is a sub-routine which contains set of statements. Usually procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
procedure_name:
;procedure body
ret