|
|
Introduction to Computer Systems
Tutorial / Laboratory 06 -
procedures
Week 7
Preparation [1 Marks]
- Read over the rPeANUt manual in relation to the frame buffer and graphics.
- Review the your strengths and weaknesses for this course (make a note of them).
Lab [4 Marks]
- Write a program in rPeANUt that fills the graphics display with white and then halts. Using the command line count how many instructions it uses (compare with others in the lab). Also dump the frame buffer to a text file (using the -dump option) and check it is the same as whitescreen.dump. Use the "diff" command.
- Write a procedure that sets a particular pixel of the graphics display to white. Use the below for the signature/stack frame for the method.
; setpixel - set a pixel to be white
; stack frame :
; return address #0
; y #-1
; x #-2
; "pixel (x,y) will be bit x%32 of the word at
; address 0x7C40 + 6*y + x/32" from spec
Test your approach with a program that set particular pixels.
- Include your setpixel method into the below program.
; for (i = 0; i < 100; i++) {
; setpixel((rand())%192,(rand())%160);
; }
0x0100 : jump loopbool
loop: push R0 ; work out x pixel
call rand
pop R0
load #192 R1
mod R0 R1 R0
push R0
push R0 ; work out y pixel
call rand
pop R0
load #160 R1
mod R0 R1 R0
push R0
call setpixel ; draw the pixel
pop R0
pop R0
load loopcount R1
add R1 ONE R1
store R1 loopcount
loopbool : load #100 R0
load loopcount R1
sub R0 R1 R1
jumpnz R1 loop
halt
loopcount : block 1
mask : block #0x7fffffff ; we need this mask so the random number is positive
; rand - generate psudo random numbers.
; this uses Linear Congruential Generator see http://en.wikipedia.org/wiki/Linear_congruential_generator
; stack frame :
; return address #0
; return random value #-1
rand : load aval R0
load rval R1
mult R0 R1 R1
load cval R0
add R1 R0 R1
store R1 rval
rotate #12 R1 R1
load mask R0
and R0 R1 R1
store R1 #-1 SP
return
rval : block #0 ; this stores the current random
aval : block #1664525
cval : block #1013904223
Now when you run the program you should see a random cloud of pixels. Use the command line and the -dump option to check that what you have is the same as what is expected. cloud.dump
|