Tom Kelliher, CS 220
Sept. 24, 1997
How to use script.
Homework due Friday.
Finish reading Chapter 3.
What is the nature of a procedure?
Steps in executing a procedure:
How do we implement this within our memory model?
f1, a function:
.data f1p1: .word # parameter 1 of function 1 f1p2: .word # parameter 2 of function 1 ... # other parameters and locals f1rv: .word # return value of function 1 f1ra: .word # return address of function 1 .text f1: ... # first instruction of f1 move f1rv, ... # store return value b (f1ra) # return
To use f1:
.text ... move f1p1, ... # load parameters ... la f1ra, ret1 # save return address b f1 # call f1 ret1: move ..., f1rv # instruction to which control returns; # extract return value
Can two procedures use the same name for a local variable?
Write a procedure to swap two .words. Write a code fragment to call the procedure.
Properties of conventional number systems:
Unsigned value of a binary integer:
Common bases: decimal, binary, octal, hexadecimal.
Use the previous summation and do all math in decimal.
Example: convert binary 110101 to decimal.
(How well do you know your powers of 2?)
Algorithm:
let dnum be the decimal number to convert; index = 0; bnum = 0; while (dnum != 0) { bnum[index] = dnum % 2; dnum = dnum / 2; index = index + 1; }
Example: convert decimal 133 to binary.
Form for octal & hexadecimal constants in C?
Conversion examples?