-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtriangle_pattern.asm
More file actions
83 lines (72 loc) · 2.86 KB
/
triangle_pattern.asm
File metadata and controls
83 lines (72 loc) · 2.86 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
76
77
78
79
80
81
82
83
; =============================================================================
; TITLE: Right-Angled Triangle Pattern
; DESCRIPTION: Generate an increasing star pattern (*) using nested loops
; to iterate through rows and columns.
; 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
ROWS DB 5 ; Total height of the triangle
MSG DB 'Right-Angled Star Triangle:', 0DH, 0AH, '$'
; -----------------------------------------------------------------------------
; CODE SEGMENT
; -----------------------------------------------------------------------------
.CODE
MAIN PROC
; Segment registers initialization
MOV AX, @DATA
MOV DS, AX
; Header text
LEA DX, MSG
MOV AH, 09H
INT 21H
MOV BL, 1 ; Number of stars for first row
MOV BH, ROWS ; Counter for total rows
; -------------------------------------------------------------------------
; OUTER ROW LOOP: Managed by BH
; -------------------------------------------------------------------------
ROW_START:
PUSH BX ; Preserve state for inner processing
; -------------------------------------------------------------------------
; INNER COLUMN LOOP: Managed by CL
; -------------------------------------------------------------------------
MOV CL, BL ; Load current star count
STAR_PRINT:
MOV DL, '*'
MOV AH, 02H
INT 21H
LOOP STAR_PRINT ; Automatically decrements CX and loops
; Print Newline (CR/LF sequence)
MOV DL, 0DH
MOV AH, 02H
INT 21H
MOV DL, 0AH
INT 21H
POP BX ; Restore counters
INC BL ; Increase star count for next row
DEC BH ; One less row to process
JNZ ROW_START ; Continue until BH is 0
; Exit
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
; =============================================================================
; TECHNICAL NOTES
; =============================================================================
; 1. LOOP ARCHITECTURE:
; - Standard nested loop architecture (O(N^2)).
; - Uses CX register with the 'LOOP' opcode for efficient inner iteration.
; - Expected Output:
; *
; **
; ***
; ****
; *****
; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =