0% found this document useful (0 votes)
9 views5 pages

Coal Cheatsheet

Very good lovely

Uploaded by

Momin Dar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Coal Cheatsheet

Very good lovely

Uploaded by

Momin Dar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

flipping function to mirror top to bottom(topL->botR)

flip:
push es
push si
push di
push cx
mov ax, 0xb800
mov es, ax
mov cx, 960
xor si, si
mov di, 3838

flip_loop:
mov ax, [es:si]
mov [es:di], ax

add si, 2
sub di, 2

loop flip_loop

pop cx
pop di
pop si
pop es
ret
/////////////////////////////////

sleep function
sleep: push cx
mov cx, 0xFFFF
delay: loop delay
pop cx
ret
//////////////////////////////////

function to swap quarters of screen(q1<->q4, q2<->q3)


swap_areas:
push es
push si
push di
push cx
mov ax, 0xb800
mov es, ax

xor si, si; starting point of q1

mov di, 2000; starting point of q4

mov cx, 480 ;swaps

swap_loop:
mov ax, [es:si]
xchg ax, [es:di]
mov [es:si], ax

add si, 2
add di, 2
loop swap_loop
pop cx
pop di
pop si
pop es
ret
////////////////////////////////

print verticle rectangle


printrec:
push es
push ax
push di
mov bx,200
mov dx,0x0741
mov ax, 0xb800
mov es, ax
mov di, bx
mov cx,22
loop1:
mov word [es:di],dx
add di,2
loop loop1
mov cx,18
loop2:
mov word [es:di],dx
add di,160
loop loop2
mov cx,22
loop3:
mov word [es:di],dx
sub di,2
loop loop3
mov cx,18
loop4:
mov word [es:di],dx
sub di,160
loop loop4
pop di
pop ax
pop es
ret 4
//////////////////////////////////

function to print line(2)


[org 0x0100]
jmp start

printline:
push ax
mov ah, 0x0e
l1:
lodsb
or al, al
jz endloop
int 0x10
jmp l1
endloop:
pop ax
ret

start:
call clearscreen

mov dl, 0

mov dh, 1 ; dl=x dh=y


mov ah, 0x02 ; set cursor position
mov bh, 0x00 ; page number
int 0x10
mov si, m1 ;message
call printline

mov ah, 0x00 ;set keyboard input


int 0x16 ;keyboard interrupt ;puts key entered in al
mov ax, 0x4c00
int 0x21
///////////////////////////////////////

make line for creating patterns


x equ 50 ;x coordinate
y equ 100 ;y coordinate
w equ 70 ;width
c equ 60 ;color attribute

code:
mov ah, 0
mov al, 13h
int 10h

call clearscreen

mov cx, x
mov dx, y
mov al, c
u1:
mov ah, 0ch
int 10h
inc cx
inc dx
cmp cx, x+w
jbe u1
/////////////////////////////////

print an array of numbers and their sum


printarray:
push si
push cx
push ax
push di
mov si, data ;array address
mov cx, 10 ;array length
mov di, 160 ;going to 2nd row (y=1)
printloop:
mov ax, [si]
push ax
call printnum
add di, 4
add si, 2 ;next array element
loop printloop
add di, 84
call sumarray
mov ax, [sum]
push ax
call printnum
pop di
pop ax
pop cx
pop si
ret

sumarray:
push si
push cx
push ax
xor ax, ax
mov si, data
mov cx, 10
sumloop:
add ax, [si]
add si, 2
loop sumloop
mov [sum], ax
pop ax
pop cx
pop si
ret
//////////////////////////////////////

find element in array


findkey:
push bp
mov bp, sp
push si
push cx
push ax
push di
mov si, [bp+8] ;address of array
mov cx, [bp+6] ;length of array
mov ax, [bp+4] ;element to look for
findloop:
cmp ax, [si]
je keyfound
add si, 2
loop findloop
mov si, m2
jmp printmessage
keyfound:
mov si, m1
printmessage:
call printline
pop di
pop ax
pop cx
pop si
pop bp
ret
////////////////////////////////////

interrupts(takes input and displays next char after a space of 2)

mov ah, 0x02


mov bh, 0x00
mov dh, 1
mov dl, 15
int 0x10

mov ah, 0x01


int 0x21 ;take input and show on screen

inc al

add dl, 2
mov ah, 0x02 ;display character
int 0x10

mov ah, 0x0E ;print char and advance cursor


mov bh, 0x00 ;page no 0
int 0x10 ;print

You might also like