Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

National University of Technology

Computer Science Department


Semester Spring – 2023
LAB REPORT - 12
Course: COAL LAB
Course Code: CS4604

Submitted To: Submitted By:


Name: Lec Yosha jawad/
Eng Syed Ahmad Raza Abdullah Khurram(F21605001)
CS Department Saad Ahmed(F21605037)
Task1:
Write a program that displays the string “Assembly Language is COOL” in four different
colors. Each word should be displayed in a different color of your choice on console.
CODE:
.686
.MODEL FLAT, STDCALL
.STACK
INCLUDE Irvine32.inc
.DATA
str1 BYTE "Assembly Language is COOL",0
.CODE
main PROC

mov eax, 10990h


mov ecx, 4; Loop should run 4 times
l1:
call randomRange ;randomRange is used so that every time a random value is
stored in eax for color of background and foreground
call SetTextColor
lea edx, str1
call WriteString
call crlf
call crlf
loop l1
exit
main ENDP
END main

SCREENSHOTS:
Task2:
Write a program that generates and displays 50 random integers between -20 and +20.
CODE:
.686
.MODEL flat, stdcall
.STACK
INCLUDE Irvine32.inc
.data
count BYTE 0
.code
main PROC
MOV ecx,50
l1:
MOV eax,-20d
call randomRange
call writeInt
call crlf
inc count
MOV eax,+20d
call randomRange
call writeInt
call crlf
inc count
loop l1
exit
main ENDP
END main

SCREENSHOTS:
Task3:
The following program demonstrates the compare instruction and the affected flags.

TITLE Demonstrating the Compare Instruction (cmp.asm)


.686
.MODEL flat, stdcall
.STACK
INCLUDE Irvine32.inc
.data
var1 SDWORD -3056
.code
main PROC
mov eax, 0f7893478h
mov ebx, 1234F678h
cmp al, bl
cmp ax, bx
cmp eax, ebx
cmp eax, var1
exit
main ENDP
END main
Carry the execution of the compare instructions. Guess the values of the flags and
write them in the specified boxes.

cmp al, bl OF =0 CF =0 SF =0 ZF =1

cmp ax, bx OF =1 CF =1 SF =0 ZF =0

cmp eax, ebx OF =1 CF =0 SF =0 ZF =0

cmp eax, var1 OF =1 CF =0 SF =0 ZF =0


Task4:
Write an assembly language program that jumps to label L1 if the expression (EBX – ECX) is
greater than zero and display some message on console. (Conditional Jump Instruction)
CODE:
;Task4
.686
.MODEL FLAT, STDCALL
.STACK
INCLUDE Irvine32.inc
.DATA
str1 BYTE "ebx is greater than ecx",0
.CODE
main PROC
mov ebx,20
mov ecx,10
cmp ebx,ecx
ja L1 ;jump to L1 if ebx is above ecx
jmp stop
L1:
lea edx,str1
call WriteString
stop:
exit
main ENDP
END main

SCREENSHOTS:

You might also like