Lab 1-2-2019

You might also like

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

COMPUTER SCIENCE AND ENGINEERING

OBAFEMI AWOLOWO UNVERSITY, ILE-IFE

CPE 301 : LOW LEVEL LANGUAGE


Harmattan 2018-19
Prepared by Dr. A. O. Oluwatope

PRACTICAL EXERCISES

Instructions:
a. The lab exercises are sectioned into two – Emu8086 and Visual MASM
b. Ensure that you demonstrate the exercises individually
c. In case of challenges get in touch with the lab attendants or myself
d. You will need to have installed the two apps on your PC or lab PC

PRACTICAL EXERCISE ONE

Part One: On Intel Emu8086

name "hi-world"

; this example prints out "hello world!"


; by writing directly to video memory.
; in vga memory: first byte is ascii character, byte that follows is character attribute.
; if you change the second byte, you can change the color of
; the character even after it is printed.
; character attribute is 8 bit value,
; high 4 bits set background color and low 4 bits set foreground color.

; hex bin color


;
;0 0000 black
;1 0001 blue
;2 0010 green
;3 0011 cyan
;4 0100 red
;5 0101 magenta
;6 0110 brown
;7 0111 light gray
;8 1000 dark gray
;9 1001 light blue
;a 1010 light green
;b 1011 light cyan
;c 1100 light red
;d 1101 light magenta
;e 1110 yellow
;f 1111 white

org 100h

; set video mode


mov ax, 3 ; text mode 80x25, 16 colors, 8 pages (ah=0, al=3)
int 10h ; do it!

; cancel blinking and enable all 16 colors:


mov ax, 1003h
mov bx, 0
int 10h

; set segment register:


mov ax, 0b800h
mov ds, ax

; print "hello world"


; first byte is ascii code, second byte is color code.

mov [02h], 'H'

mov [04h], 'e'

mov [06h], 'l'

mov [08h], 'l'

mov [0ah], 'o'

mov [0ch], ','

mov [0eh], 'W'

mov [10h], 'o'


mov [12h], 'r'

mov [14h], 'l'

mov [16h], 'd'

mov [18h], '!'

; color all characters:


mov cx, 12 ; number of characters.
mov di, 03h ; start from byte after 'h'

c: mov [di], 11101100b ; light red(1100) on yellow(1110)


add di, 2 ; skip over next ascii code in vga memory.
loop c

; wait for any key press:


mov ah, 0
int 16h

ret

Activities:

1. Launch the Emu8086, create a new file using the “COM template “ and copy the program
2. Click on “ Compile Button”, then save the file with the suggested file name and click on
“ Run Button”
3. Observe the output of the program as depicted in the figure 1.0
Figure 1.0: Output Screenshot

4. Modify the program above to display “ Great Ife, Oba Awon University” with the
background color = light blue and foreground color = green

Part Two: On Visual MASM

; *************************************************************************
; 32-bit Windows Console Hello World Application - MASM32 Example
; EXE File size: 2,560 Bytes
; Created by Visual MASM (http://www.visualmasm.com)
; *************************************************************************

.386 ; Enable 80386+ instruction set


.model flat, stdcall ; Flat, 32-bit memory model (not used in 64-bit)
option casemap: none ; Case insensitive syntax

; *************************************************************************
; MASM32 proto types for Win32 functions and structures
; *************************************************************************
include c:\masm32\include\kernel32.inc
include c:\masm32\include\masm32.inc

; *************************************************************************
; MASM32 object libraries
; *************************************************************************
includelib c:\masm32\lib\kernel32.lib
includelib c:\masm32\lib\masm32.lib

; *************************************************************************
; Our data section. Here we declare our strings for our message
; *************************************************************************
.data
strMessage db "Hello World!",0

; *************************************************************************
; Our executable assembly code starts here in the .code section
; *************************************************************************
.code

start:
; Use the StdOut API function to display the text in a console.
invoke StdOut, addr strMessage

; When the console has been closed, exit the app with exit code 0
invoke ExitProcess, 0
end start

Activities

1. Launch the Visual MASM app and create a new Assembly file as a ” 32-bit Windows
Console Application”
2. Assemble the program and Run.
3. Save the file with a name or accept the default names

4. If the program assembled and linked successfully, you have see the following in the “
Output Window”
*******************************

Assembling project Win32Con.exe

*******************************

Assembling: C:\Program Files (x86)\Visual MASM\Projects\Win32Con\Assembly1.asm

Created "C:\Program Files (x86)\Visual MASM\Projects\Win32Con\Release\Assembly1.obj"


(618 bytes)

****************************

Linking project Win32Con.exe

****************************

Created "C:\Program Files (x86)\Visual MASM\Projects\Win32Con\Release\Win32Con.exe"


(2560 bytes)

5. Type “cmd” at the start button on the Desktop to switch to the console
6. At the C: prompt, type “cd C:\Program Files (x86)\Visual
MASM\Projects\Win32Con\Release “
7. List the directory with “ Dir” and locate the executable file “ Win32con.exe”
8. Type the filename at the prompt and observe the output “ Hello World”
9. Modify the program to display “ Great Ife! Oba Awon University”

Part Three:

1. Launch the Visual MASM app and create a new Assembly file as a ” 32-bit Windows
MessageBox Application”
2. Repeat step 2-4 ( in Part Two above)
3. If your program execute successfully, you should see the following in your output
window

************************************************************************
**********

Compiling resource C:\Program Files (x86)\Visual


MASM\Projects\Win32App\Resource.rc

************************************************************************
***********
Microsoft (R) Windows (R) Resource Compiler, Version 5.00.1823.1 - Build 1823

Copyright (C) Microsoft Corp. 1985-1998. All rights reserved.

Using codepage 1252 as default

Creating C:\Program Files (x86)\Visual


MASM\Projects\Win32App\Release\Resource.res

RC: RCPP -CP 1252 -f C:\Program Files (x86)\Visual


MASM\Projects\Win32App\Release\RCa04408 -g C:\Program Files (x86)\Visual
MASM\Projects\Win32App\Release\RDa04408 -DRC_INVOKED -D_WIN32 -pc\:/ -E -
I. -I C:\Program Files (x86)\Visual MASM\Projects\Win32App\ -I .

C:\Program Files (x86)\Visual MASM\Projects\Win32App\Resource.rc.

Writing 24:1, lang:0x409, size 418

Created "C:\Program Files (x86)\Visual


MASM\Projects\Win32App\Release\Resource.res" (484 bytes)

****************************

Linking project Win32App.exe

****************************

Created "C:\Program Files (x86)\Visual


MASM\Projects\Win32App\Release\Win32App.exe" (3584 bytes)
4. Your output message appears in a messagebox. See the figure below

5. Modify the program to display in the MessageBox “ Great Ife! Oba Awon University”
with a Title “ Ogba Obafemi”

You might also like