Skip to content

Instantly share code, notes, and snippets.

@TunaYagci
Created April 18, 2017 21:07
Show Gist options
  • Save TunaYagci/ebe27aeea96a8265ea63dbaa6406fa26 to your computer and use it in GitHub Desktop.
Save TunaYagci/ebe27aeea96a8265ea63dbaa6406fa26 to your computer and use it in GitHub Desktop.
Assembly Triangle
;Tuna Yağcı
org 100h
;write char from al
writeChar MACRO
mov ah, 2
mov dl, al
int 21h
ENDM
;------------------
;newLine
newLine MACRO
mov dx,13
mov ah,2
int 21h
mov dx,10
mov ah,2
int 21h
ENDM
;--------
;star
star MACRO
mov al, '*'
writeChar
ENDM
;--------
;space
space MACRO
mov al, ' '
writeChar
ENDM
;--------
;spaceFor---
spaceFor MACRO spaceCount
LOCAL loop123
mov sp, 82h
push cx
mov cx, spaceCount
loop123:
space
loop loop123
mov sp, 80h
pop cx
ENDM
;------------
;starFor---
starFor MACRO spaceCount
LOCAL loop123
mov sp, 82h
push cx
mov cx, spaceCount
loop123:
star
loop loop123
mov sp, 80h
pop cx
ENDM
;------------
;sayacArttir
sayacArttir MACRO
mov sp, 90h
pop ax
inc ax
mov sp, 92h
push ax
mov sp, 40h ;don't use here
ENDM
;-----------
;triangleFillingWithSpaceAndStar
triangleFillingWithSpaceAndStar MACRO
dec ax
mov bx, 2
mul bx
dec ax
spaceFor ax
star
ENDM
;----------------------
triangleFillingWithStarAndStar MACRO
dec ax
mov bx, 2
mul bx
dec ax
starFor ax
star
ENDM
;open gui
mov al, 13h
mov ah, 0
int 10h
;-------
;write height
writeHeightAndAsk MACRO
mov dx, offset heightMSG
mov ah, 9
int 21h
askHeight
ENDM
;-----------
;print height user just entered
printWritedHeight MACRO
writeChar
ENDM
;------------------------------
askHeight MACRO
mov ah, 00h
int 16h
ENDM
;--------------
;MAIN;
TRIANGLE MACRO
writeHeightAndAsk
dec ah
mov cl, ah
printWritedHeight
l1:
newLine
sayacArttir
mov ax, cx
dec ax
cmp ax, 0
je limitReached
spaceFor ax
star
mov sp, 90h ;sayac check
pop ax
mov sp, 40h;don't use here
cmp ax, 1
ja aboveOne
jmp notAboveOne
limitReached:
star
mov sp, 90h ;sayac check
pop ax
triangleFillingWithStarAndStar
hlt
jmp notAboveOne
aboveOne: ;spaceCount is ((ax-1)*2)-1
triangleFillingWithSpaceAndStar;CHANGE THIS LINE TO triangleFillingWithStarAndStar TO FILL WITH STAR
notAboveOne:
loop l1
ENDM
RECTANGLE MACRO
heightLoop:
mov cx, height
mov cx, width
widthLoop:
star
loop widthLoop
newLine
mov cx, height
dec height
loop heightLoop
ENDM
RECTANGLE
TRIANGLE
hlt
heightMSG db "Enter height: $"
nextLineMSG db "\n $"
height DW 4
width DW 6
@TunaYagci
Copy link
Author

Prints a triangle and rectangle with given height.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment