-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q2b Binary to BCD 16Bits.asm
55 lines (33 loc) · 1.48 KB
/
Q2b Binary to BCD 16Bits.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
; Q2b BCD conversion Binary to BCD
org 100h
.DATA
BIN_IN DW 0078H ; Binary Input Variable
BCD_OUT DW ? ; Binary Output Varibale
.CODE
.STARTUP
CALL BIN_TO_BCD
.EXIT
BIN_TO_BCD PROC NEAR
PUSHF ; Pushing the registers value into the stack
PUSH BX
PUSH CX
PUSH DX
L1: MOV AX, BIN_IN ; Storing the BCD input in AL register
MOV BX, 000AH ; Initilising BL with 0AH
DIV BX ; Dividing AL (Dividend) with BL (Divisor), Quotient goes in AL, and remainder in AH
CMP AL, 0AH
JC SKIP
ADD AL, 06H
SKIP:MOV CL, 04H ; Initilising CL with 04H
SHL AX, CL ; Using Shift left instruction to shift Lower Order nibble to Higher order and making Lower order nibble 0H
ADD AX, DX ; Adding the AL with AH (remainder), and sum gets stored in AL
AND DX, 0000H
MOV BCD_OUT, AX ; Storing the sum to out output variable
DEC BIN_IN
JNZ L1
POP DX ; Poping the registers value from the stack in LIFO order
POP CX
POP BX
POPF
BIN_TO_BCD ENDP
END