Week 11 A
Week 11 A
System Programming
November 21, 2006
Today’s Topics (1/2)
• Assignment 3
– Windows (graphics mode) programming.
– Linking to an assembly procedure.
– Setting up Visual C++ 2005 Express.
References
• Setting up Platform SDK: see the course
webpage.
• Setting up Visual C++ 6.0 to compile and
link assembly code with C or C++ code:
included in the download file
• theForger’s Win32 API Tutorial
http://winprog.org/tutorial. (Read at least
the first two articles.)
Demo
• The program creates a “mosaic” effect on
your windows desktop.
• You need to set your display to use 24-bit
or 32-bit colors.
• Using ML.exe /Zi option to enable
debugging directly within your assembly
code at Visual C++. (Already done for you
if you use VC++ 2005 Express.)
Assembly Code to Be Written
Mosaic(img, resX, resY,
x, y, blockX, blockY)
Example Code
• Mosaic_C_version() in main.c shows
the algorithm.
• To run the assembly code, remember to
comment out:
#define MOSAIC_C_VERSION
• The Mosaic procedure in mosaic.asm
gives an example of accessing parameters
and local variables.
Img: a 2D Array
• The img[] is conceptually 2D, but stored as if it
is a 1D array.
• A pixel at location (x, y) is stored at
img[x + y * xRes]
• Each pixel stores the Red, Green, Blue
components of a color in 4 bytes:
struct {
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} RGBQUAD;
Basic Structure of a Windows
Program
• WinMain procedure.
• WinProc procedure.
• Section 11.2 explains the above in
assembly. The C version in main.c might
be easier to read.
• An excellent introductory material can be
found at: http://winprog.org/tutorial. (Read
at least the first two articles.)
WinMain Procedure
Every Windows application needs a startup
procedure, usually named WinMain, which is
responsible for the following tasks:
WinProc PROC,
hWnd:DWORD, ; handle to the window
localMsg:DWORD, ; message ID
wParam:DWORD, ; parameter 1 (varies)
lParam:DWORD ; parameter 2 (varies)
• Memory
– Memory consists of 8-bit bytes
– Any 3 consecutive bytes form a word (24 bits)
– Total of 32768 (215) bytes in the computer
memory
SIC Machine Architecture (2/7)
• Registers
– Five registers
– Each register is 24 bits in length
8 1 15
opcode x address
• Addressing Modes
– There are two addressing modes available
• Indicated by x bit in the instruction
• Registers
– Additional registers are provided by SIC/XE
1 11 36
s exponent fraction
F*2(e-1024)
SIC/XE Machine Architecture (4/13)
• Instruction Formats
8
Format 1 (1 byte)
op
8 4 4
Format 2 (2 bytes) op r1 r2
6 1 1 1 1 1 1 12
Format 3 (3 bytes) op n i x b p e disp
6 1 1 1 1 1 1 20
Format 4 (4 bytes)
op n i x b p e address
n i x b p e
opcode 1 1 1 0 0 disp
n i x b p e
opcode 1 1 disp