SEAC, 1945, first computer with a stored program capability. Word-addressable with a word length of 46bits. Manipulate with octal numbers.
How many memory words in SEAC? What does stored program mean?
Example: Write a program to find out when the artillery shell hits the ground.
, initially ; .
Three-address format – modified SEAC
No D address, need PC
12 bits per address
Questions: How many words the computer can address? Which instructions need to be modified? And how?
General-purpose register (register-register, load-store) computer falls this category.
Two-address format – modify SEAC again to reduces its addresses to two
6bytes per instruction, 18 bits per address, much larger memory
Question: how to avoid the overwritten of A in A [A]+[B]?
Many transistorized computers used a two-address format with the assistance of ACC as the register for the operation result, thus eliminating the data transfer to retain the value in A.
One-address format: only one address A remains. The other operand comes from ACC; result goes to ACC.
Branching and Condition Codes: Instead of using compp and compn, many computers use condition codes in a Status register that specify the state of the result of the last operation. Typical condition codes are: N, Z, V, C
Branch positive, branch negative, etc
specify how a computer can access its operands and store the result in its registers and main memory.
Immediate addressing: operand is given as part of the instruction, suitable for small integers for ALU; eg. Addi
Register Addressing: The address of an operand is a register.
Direct Addressing: also called absolute addressing. The first method used by electronic stored-program computers. The address in main memory is included in the instruction to obtain data. Any shortcomings?
Indirect Addressing: the content of a register is the main memory address of the operand. Eg. LDW R1, (R2)
Example: Sum integers. Page 12. Steps: register allocation; initialization; do the job; store result.
Indexing and Arrays: Indexing is a technique that allows a value to be added to the content of a register (called index register) to form an effective address.
Eg. ADD R3, C(R2) EA = C+[R2], C is called displacement or offset
Example applications: C can hold the address of the first element in an array and the index register is initialized to 0 and then index into the array.
Eg. ADD R3, (R1)(R2) Example: re-do the example of summing integers. The modifier field in SEAC machine.
Base and Indexing Addressing:
Base, Index, and Offset Addressing:
Relative Addressing: EA = [PC]+displacement for target address computation.
Autoincrement and Autodecrement: Designed for push and pop in stack operation
Eg. (Rx)+ for autoincrement and –(Rx) for autodecrement.
The Assembler Definition: Assembler is a program that translates the assembly code into machine code.
The structure of a sentence in an assembly language has 4 parts:
A label: optional, stands for the name of the location of an instruction of a piece of data
eg. Msg1: .string “Hello World!”
A mnemonic: stands for the operation
Addresses for the operands and result: register number, or memory address, or a constant
The set of rules that define each instruction type and how it can be used is called the syntax of the assembly language.
How does an assembler translate an assembly code into object code?
Two-pass assembler as an example.
Find out the label(variable)-address pairs (insert them into a symbol table); changes the operation to the binary op code; change decimal numbers to binary, etc.
Do the translation based on instruction format to get the machine code.
Question: How to assemble external variables? (eg. printf in c)
Answer: Seek the help of linker.
Directives: direct/assist the assembler to do its job (to understand the desire of the programmer)! (start, text, data, etc)
Directives are reserved words! They are not instructions!
Possible Directives for an assembler: Label Directives Operand
B EQU 300
LIST RESERVE 320
N DATAWORD 200
JAKE DATABYTE 15
Example: Sum the N integers (Page 20-22)
Syntax of the instructions get the instruction format
Loader is used to load the executable into the main memory and assign a new address to each variable/label. Why?
Typical Instructions Integer Arithmetic Instructions: +,-, *, /; addressing mode, HI and LO registers for mul and div, etc.
Floating-Point Arithmetic Instructions: +,-, *, /, and/or sqrt. Trigonometric functions are done through subprograms using a technique called numerical analysis.
Decimal Arithmetic Instructions: use BCD code
Data Conversion Instructions: integer to/from FP
Shifting Instructions: logical/arithmetic shift, to do multiplication, etc
Logic Instructions: and, or, not, xor, etc. used to isolate a given set of bits in a register. To set values, etc.
Word and Byte Transmission Instructions: LDW/STW, LDB/STB, etc.
Control and Branch Instructions: comparison based or condition code based; A control instruction is a compare: set the condition code based on comparison result.
Sense Indicators and Status Instructions: bits in the status register! Test and set (TST #n Rx).
Input/Output Data transfer between the main memory and I/O devices is controlled by OS. Why? – conflict avoidance!
Large mainframe computers use I/O channels for data movement. Smaller computers have simple I/O paths – our focus!
There exist two methods of performing I/O in small computers: program-controlled I/O and memory-mapped I/O.
Need synchronization – the speed of I/O devices and the speed of the main memory are different
Buffer registers and status registers residing in the control unit of the device: DIN and DOUT, SIN and SOUT
Eg. Type a character from the keyboard and display a character in the monitor.
SPECIAL BRANCH instruction is needed to perform the job:
WAITIN BIN WAITIN
STB Constant(R3), DIN
WAITOUT BOUT WAITOUT
LDB Constant(R3), DOUT
Efficiency: -- the speed of the computer is slowed down to that of the device!
Computer does not need to know DIN and DOUT. Each I/O device buffer is wired through an interface to move data to or from a particular location in main memory.
DIN is mapped to the special location DATAIN in the main memory and DOUT is mapped to the special location DATAOUT in the main memory. These locations are reserved by OS and can not be modified by the user.
WAITIN BIN WAITIN
WAITOUT BOUT WAITOUT
Special BRANCH instructions such as BIN and BOUT can be avoided by using TST instruction and the status register.
WAITIN TST #3, R1
BEZ R1, WAITIN
WAITOUT TST #4, R1
BEZ R1, WAITOUT
No efficient in CPU usage again!
Computer checks the status either by polling the status register or it is interrupted by the I/O devices if interrupt-driven method is applied.
Stacks Stack grows from high address to low address
TOS and BOS are well-defined. Initially SP points to the address just above BOS. SP always point to TOS
How to implement PUSH and POP operations? What if the machine supports autoincrement and autodecrement addressing?
Queues Queue is a data structure that implements FIFC.
Definition: A subroutine is a set of instructions that will be used multiple times by a program over different data . A subroutine usually has a name (label), which indicates the location of the subroutine program in the main memory.
To use a subroutine, we need an instruction CALL. The subroutine is the called program (callee) and the main program is the caller program (caller).
Procedure call is a special branch operation, in which the control will be transferred from the caller to the callee. The callee needs to return the control back the caller when its job is finished. This is done by an instruction called RETURN.
Subroutine linkage protocol: Caller saves the return address in the link register and then makes a procedure call. Callee branches to the address stored in the link register when done.
Nested subroutines: subroutine A calls subroutine B, etc,
In nested subroutine calling, return address will be overwritten! – stack.
Who will save and when to save the return address into the stack? – callee at the beginning.
Parameter passing: calling parameters and returned parameter are passed by registers or by the stack.
Turn the integer sum example into a procedure (subroutine).
Procedure call summary: -- six steps:
Pass parameters to callee
Register or stack
Transfer control to the procedure
Allocate storage resources
Save return address register and locally used registers into the stack
Perform the desired task
Transfer control to the caller
Stack frame: The space on the stack that is used to pass parameters and save/restore registers is called a stack frame. The frame pointer for a particular subroutine remains fixed throughout the invocation of that instance of the subroutine.
Frame pointer points to the address that saves the frame pointer of the caller!
Use frame pointer to access data within the stack frame!