Created
March 31, 2018 19:59
-
-
Save HamedMasafi/44064a5b0cdb3701172802fccf04bc1f to your computer and use it in GitHub Desktop.
Iran's flag assembly sample code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;---------------------------------- | |
; | |
; Iran flag | |
; Hamed Masafi | |
; [email protected] | |
; | |
;---------------------------------- | |
stacksg segment stack | |
db 32 dup("stack---") | |
stacksg ends | |
datasg segment para 'data' | |
x dw 70 ; x of flag position | |
y dw 50 ; y of flag position | |
xstep dw 1 ; x-axe movement direction (1 for right and -1 for left) | |
ystep dw 1 ; y-axe movement direction (1 to bottom and -1 for top) | |
wind dw 0 ; wind salt parametere | |
col dw ? ; current column in draw loops | |
row dw ? ; current row in draw loops | |
; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
waves db 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 5, 6, 6, 6, 7, 7, 7 ; array table for wave simulation | |
allah db 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0 | |
db 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 | |
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | |
db 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0 | |
db 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0 | |
db 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0 | |
db 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0 | |
db 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0 | |
db 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1 | |
db 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1 | |
db 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1 | |
db 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1 | |
db 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1 | |
db 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0 | |
db 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0 | |
db 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0 | |
db 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0 | |
db 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 | |
db 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 | |
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 | |
_width equ 540 | |
_height equ 400 | |
datasg ends | |
codesg segment para 'code' | |
main proc far | |
assume ds:datasg, cs:codesg, ss:stacksg | |
mov ax, datasg | |
mov ds, ax | |
; set graphical mode | |
mov ah, 00h | |
mov al, 12h | |
int 10h | |
;main loop | |
loop_flag_mov: | |
mov cx, 60 | |
row_loop: | |
mov row, cx | |
push cx | |
mov cx, 80 | |
col_loop: | |
mov col, cx | |
push cx | |
; calculate wave level | |
mov cl, 34 | |
mov ax, col | |
add ax, wind | |
div cl | |
cmp ah, 17 ; if | |
jl ah_is_less_than_5 ; then | |
mov dl, 34 | |
sub dl, ah | |
mov ah, 2 | |
jmp ah_is_greatter_than_5 | |
ah_is_less_than_5: ; else | |
mov dl, ah | |
mov ah, 1 | |
ah_is_greatter_than_5: | |
; select color for dark side of flag | |
mov al, 07 ; set white color | |
cmp row, 20 | |
jg no_green_color | |
mov al, 02 ; set green color | |
no_green_color: | |
cmp row, 40 | |
jl no_red_color | |
mov al, 04 ; set red color | |
no_red_color: | |
push ax | |
push bx | |
push cx | |
push dx | |
cmp al, 07 ; if color == white | |
jne is_not_white | |
cmp col, 30 | |
jl is_not_white | |
cmp col, 50 | |
jg is_not_white | |
; calculate row and col in allah image | |
mov ax, row | |
mov cx, col | |
add ax, -20 | |
add cx, -30 | |
mov si, cx | |
mov bl, 20 | |
mul bl | |
mov bx, ax | |
; comare if in allah image curent point is equal to 1 | |
cmp allah[si][bx], 1 | |
jne is_not_white | |
jmp set_allah_color_begin | |
is_not_white: | |
pop dx | |
pop cx | |
pop bx | |
pop ax | |
jmp set_allah_color | |
set_allah_color_begin: | |
pop dx | |
pop cx | |
pop bx | |
pop ax | |
mov al, 04 | |
set_allah_color: | |
; find wave level | |
mov dh, 0 | |
lea bx, waves | |
mov di, dx | |
mov dl, ds:[bx][di] | |
; make color lighter | |
cmp ah, 1 | |
je after_color_select | |
add al, 8 | |
after_color_select: | |
; if wave level >= 7 make gradient | |
cmp dl, 7 | |
jge xor_color | |
; if wave level <= 1 make gradient | |
cmp dl, 1 | |
jle xor_color | |
jmp after_xor | |
xor_color: | |
push ax | |
mov cl, 2 | |
mov ax, row | |
add ax, col | |
div cl | |
cmp ah, 1 | |
jne finish_xor_color | |
pop ax | |
xor al, 08 ; make color dark if is light and light if is dark | |
jmp after_xor | |
finish_xor_color: | |
pop ax | |
after_xor: | |
; black color for first row | |
cmp row, 4 | |
jg not_first_row | |
mov al, 0 | |
not_first_row: | |
; black color for last row | |
cmp row, 57 | |
jl not_last_row | |
mov al, 0 | |
not_last_row: | |
; black color for first col | |
cmp col, 1 | |
jne not_first_col | |
mov al, 0 | |
not_first_col: | |
; black color for last col | |
cmp col, 80 | |
jne not_last_col | |
mov al, 0 | |
not_last_col: | |
; set a pixel | |
mov ah, 0Ch | |
mov bh, 0 | |
mov cx, x | |
add cx, col | |
add dx, y | |
add dx, row | |
int 10h | |
pop cx | |
loop col_loop | |
pop cx | |
loop row_loop | |
; change movment direction | |
mov ax, xstep | |
add x, ax | |
mov ax, ystep | |
add y, ax | |
; check if flag reach right og screen | |
cmp x, _width | |
jne x_ne_width | |
mov xstep, -1 | |
x_ne_width: | |
; check if flag reach left og screen | |
cmp x, 1 | |
jne x_ge_1 | |
mov xstep, 1 | |
x_ge_1: | |
; check if flag reach bottom og screen | |
cmp y, _height | |
jne y_ne_height | |
mov ystep, -1 | |
y_ne_height: | |
; check if flag reach top og screen | |
cmp y, 1 | |
jne y_ge_1 | |
mov ystep, 1 | |
y_ge_1: | |
; add wind salt and reset it if reach 34 | |
add wind, 3 | |
cmp wind, 34 | |
jl wind_change | |
mov wind, 00h | |
wind_change: | |
; quit program if keyboard buffer contain a key | |
mov ah, 11h | |
int 16h | |
je loop_flag_mov | |
; restore to text mode | |
mov ah, 00h | |
mov al, 03h | |
int 10h | |
; return to dos | |
mov ax, 4c00h | |
int 21h | |
main endp | |
codesg ends | |
end main | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment