Micro Lab 3

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

Microprocessor and Assembly Language Programming

Microlink Information Technology College

LAB-3
Objective: Students will learn Assembly programming Irvine procedure, and
explore simple Assembly Language procedure in assembly and run them.

Lab Work -1:


As the first example we will see the testing color. Each student should run the
program and should try to trace it as well.

; Testing Colors (colors.asm)

; Testing SetTextColor and GetTextColor.

INCLUDE Irvine32.inc

.data
str1 BYTE "Sample string, in color",0dh,0ah,0

.code
main PROC

mov ax,yellow + (blue * 16)


call SetTextColor

mov edx,OFFSET str1


call WriteString

call GetTextColor
call DumpRegs

exit
main ENDP

END main
Lab Work -2 :
As the second example we will see the Clrscr, Crlf, DumpMem, ReadInt,
SetTextColor, ; WaitMsg, WriteBin, WriteHex, and WriteString procedures. Each
student should run the program and should try to trace it as well.

; Library Test #1: Integer I/O (InputLoop.asm)

; Tests the Clrscr, Crlf, DumpMem, ReadInt, SetTextColor,


; WaitMsg, WriteBin, WriteHex, and WriteString procedures.

INCLUDE Irvine32.inc

.data
COUNT = 4
BlueTextOnGray = blue + (lightGray * 16)
DefaultColor = lightGray + (black * 16)

arrayD SDWORD 12345678h,1A4B2000h,3434h,7AB9h

prompt BYTE "Enter a 32-bit signed integer: ",0

.code
main PROC

; Set text color to blue text on a light gray background

mov eax,BlueTextOnGray
call SetTextColor
call Clrscr ; clear the screen

; Display an array using DumpMem.

mov esi,OFFSET arrayD ; starting OFFSET


mov ebx,TYPE arrayD ; doubleword = 4 bytes
mov ecx,LENGTHOF arrayD ; number of units in arrayD
call DumpMem ; display memory

; Ask the user to input a sequence of signed integers

call Crlf ; new line


mov ecx,COUNT

L1: mov edx,OFFSET prompt


call WriteString
call ReadInt ; input integer into EAX
call Crlf ; new line

; Display the integer in decimal, hexadecimal, and binary

call WriteInt ; display in signed decimal


call Crlf
call WriteHex ; display in hexadecimal
call Crlf
call WriteBin ; display in binary
call Crlf
call Crlf
Loop L1 ; repeat the loop

; Return console window to default colors.


call WaitMsg ; "Press any key..."
mov eax,DefaultColor
call SetTextColor
call Clrscr

exit
main ENDP
END main

Lab Work -3:


As the third example we will see the MsgBox procedure. Each student should run
the program and should try to trace it as well.

; MsgBox demo (msgbox.asm)

INCLUDE Irvine32.inc

.data
caption db "Dialog Title", 0

HelloMsg BYTE "This is a pop-up message box.", 0dh,0ah


BYTE "Click OK to continue...", 0
.code
main PROC

mov ebx,0 ; no caption


mov edx,OFFSET HelloMsg ; contents
call MsgBox

mov ebx,OFFSET caption ; caption


mov edx,OFFSET HelloMsg ; contents
call MsgBox

exit
main ENDP

END main
--------------second example -------------------------
; MsgBoxAsk demo (msgboxAsk.asm)

INCLUDE Irvine32.inc

.data
caption BYTE "Survey Completed",0
question BYTE "Thank you for completing the survey."
BYTE 0dh,0ah
BYTE "Would you like to receive the results?",0
results BYTE "The results will be sent via email.",0dh,0ah,0
.code
main PROC

mov ebx,OFFSET caption


mov edx,OFFSET question
call MsgBoxAsk
;(check return value in EAX)

exit
main ENDP

END main
Lab Work -4:
As the fourth example we will see the reversing a string using stack. Each student
should run the program and should try to trace it as well.
; Reversing a String (RevStr.asm)
; This program reverses a string.

.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
.data
aName byte "Abraham Lincoln",0
nameSize = ($ - aName) - 1

.code
main proc

; Push the name on the stack.

mov ecx,nameSize
mov esi,0

L1: movzx eax,aName[esi] ; get character


push eax ; push on stack
inc esi
loop L1
; Pop the name from the stack in reverse
; and store it in the aName array.

mov ecx,nameSize
mov esi,0

L2: pop eax ; get character


mov aName[esi],al ; store in string
inc esi
loop L2
Invoke ExitProcess,0
main endp
end main
Lab Work -5:
As the fifth example we will see the Irvine procedures. Each student should run the
program and should try to trace it as well.

; Testing the Irvine32 Library procedures.

INCLUDE Irvine32.inc

TAB = 9 ; ASCII code for Tab

.code
main PROC
call Randomize ; init random generator
call Rand1
call Rand2
exit
main ENDP

Rand1 PROC
; Generate ten pseudo-random integers.
mov ecx,10 ; loop 10 times

L1: call Random32 ; generate random int


call WriteDec ; write in unsigned decimal
mov al,TAB ; horizontal tab
call WriteChar ; write the tab
loop L1

call Crlf
ret
Rand1 ENDP

Rand2 PROC
; Generate ten pseudo-random integers between -50 and +49
mov ecx,10 ; loop 10 times

L1: mov eax,100 ; values 0-99


call RandomRange ; generate random int
sub eax,50 ; vaues -50 to +49
call WriteInt ; write signed decimal
mov al,TAB ; horizontal tab
call WriteChar ; write the tab
loop L1

call Crlf
ret
Rand2 ENDP

END main
H.W. 3 (deadline: two week)
1. Write a program that displays a single character in all possible combinations of
foreground and background colors (16 x 16 = 256). The colors are numbered from
0 to 15, so you can use a nested loop to generate all possible combinations.

2. Write a procedure that produces N values in the Fibonacci number series and
stores them in an array of doubleword. Input parameters should be a pointer to an
array of doubleword, a counter of the number of values to generate. Write a test
program that calls your procedure, passing N = 47. The first value in the array will
be 1, and the last value will be 2,971,215,073. Use the Visual Studio debugger to
open and inspect the array contents.

You might also like