-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmultiplication_8bit_unsigned.asm
More file actions
75 lines (65 loc) · 2.81 KB
/
multiplication_8bit_unsigned.asm
File metadata and controls
75 lines (65 loc) · 2.81 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
; =============================================================================
; TITLE: 8-bit Unsigned Multiplication Demo
; DESCRIPTION: This program demonstrates the multiplication of two 8-bit unsigned
; integers. It illustrates how the 8086 automatically expands
; the product into a 16-bit register (AX) to prevent data loss
; from overflow.
; AUTHOR: Amey Thakur (https://github.com/Amey-Thakur)
; REPOSITORY: https://github.com/Amey-Thakur/8086-ASSEMBLY-LANGUAGE-PROGRAMS
; LICENSE: MIT License
; =============================================================================
.MODEL SMALL
.STACK 100H
; -----------------------------------------------------------------------------
; DATA SEGMENT
; -----------------------------------------------------------------------------
.DATA
; Inputs (8-bit bytes)
VAL8_1 DB 0EDH ; 237 decimal
VAL8_2 DB 99H ; 153 decimal
; Output (16-bit Product)
PRODUCT DW ? ; 237 * 153 = 36261 (8DA5H)
; -----------------------------------------------------------------------------
; CODE SEGMENT
; -----------------------------------------------------------------------------
.CODE
MAIN PROC
; --- Step 1: Initialize Data Segment ---
MOV AX, @DATA
MOV DS, AX
; --- Step 2: Load Operands ---
; For 8-bit multiplication, the first operand MUST be in AL.
MOV AL, VAL8_1
MOV BL, VAL8_2
; --- Step 3: Perform Unsigned Multiplication ---
; Result is automatically stored in the full AX register.
MUL BL
; --- Step 4: Store Result ---
MOV PRODUCT, AX
; --- Step 5: Finalize ---
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
; =============================================================================
; TECHNICAL NOTES & ARCHITECTURAL INSIGHTS
; =============================================================================
; 1. MUL OPERAND MATCHING:
; The 8086 supports two multiplication modes based on operand size:
; - Byte Multiplication: AL * Reg8 -> AX (Result)
; - Word Multiplication: AX * Reg16 -> DX:AX (Result)
;
; 2. THE CARRY & OVERFLOW FLAGS (CF/OF):
; After 'MUL BL', if the product requires the upper half (AH), CF and OF
; are set. This allows quick overflow detection.
;
; 3. ACCUMULATOR BOTTLENECK:
; One operand is always implicitly tied to the accumulator (AL or AX).
;
; 4. SIGNED MULTIPLICATION:
; Use the 'IMUL' instruction for signed (Two's Complement) products.
;
; 5. PERFORMANCE:
; Multiplication is a cycle-heavy operation. On an original 8086,
; 'MUL BL' can take between 70 to 77 clock cycles.
; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =