Course Review for Final Exam

CS 301 Lecture, Dr. Lawlor

Here's a compressed summary of the topics we've covered in the entire class so far.  See the lecture notes for all the gory details.
There will be questions on the final covering everything, from bits to function calls.  But the exam's coverage will mostly be on the performance and floating-point stuff we've done since the midterm.

Examples


global foo
foo:
; Save registers
push ebx
push esi
push edi

; Figure out how many values are coming
extern read_input
call read_input
; eax == number of elements to read
mov esi,0 ; i
mov edi,eax ; n

; Allocate space for read-in values
imul eax,4 ; number of bytes to allocate
push eax
extern malloc
call malloc
add esp,4 ; clean off stack
mov ebx,eax; ebx == pointer to malloc'd region

; Loop over input values,
; for (i=0;i<n;i++) arr[i]=read_input();
jmp loopcompare ; subtle: need this for n<=0 case...
loopstart:
call read_input
mov DWORD[ebx + 4 * esi],eax
inc esi
loopcompare:
cmp esi,edi
jl loopstart

; Print out our array of input values
push edi; number of ints to print
push ebx ; pointer to ints to print
extern iarray_print
call iarray_print
add esp,8 ; clean stack

; Clean up allocated memory
push ebx
extern free
call free
add esp,4

; Restore registers and return
pop edi
pop esi
pop ebx
ret

(Try this in NetRun now!)

global foo
foo:
extern read_input
call read_input

; Don't print if the number is <= 8
cmp eax,8
jle skip_it

; Convert eax to float, multiply by pi, store to myRet
cvtsi2ss xmm1,eax
movss xmm2,DWORD[myPI]
mulss xmm1,xmm2
movss DWORD[myRet],xmm1

; Print out myRet
push 1; number of floats to print
push myRet
extern farray_print
call farray_print
add esp,8 ; clean stack

skip_it:
jmp foo ; keep re-running read_input and our little function

ret

section .data
myPI:
dd 3.14159265358979
myRet:
dd 0.0

(Try this in NetRun now!)