Beruflich Dokumente
Kultur Dokumente
University of Waterloo
ECE 222
Digital Computers
Hiren Patel
NOTE:
HVZM6
2.12.14
NOTE:
The IEEE 1541 standard for binary prefixes was
officially adopted by the IEEE in 2005 but the binary
prefixes have not yet seen widespread use in the
computer industry.
Word 1 0 1 2 3 Word 1 3 2 1 0
Word 2 4 5 6 7 Word 2 7 6 5 4
NOTE: NOTE:
The most significant byte is The least significant byte is
assigned to address 0. assigned to address 0.
Byte Values
Memory Address
Big-Endian Little-Endian
0x0000 0x0A 0x0D
0x0001 0x0B 0x0C
0x0002 0x0C 0x0B
0x0003 0x0D 0x0A
NOTE:
The least significant byte is 0x0D and
the most significant byte is 0x0A.
0x0000 Word 0
0x0004 Word 1
0x0008 Word 2
..
.
4n Word n
17
R1 [LOC1]
R3 [LOC1] + [LOC2]
LOC1 [R1]
18
Example
Transfer contents from memory location LOC1 to register R1 is the
following:
Load dest, src Load R1, LOC1
Example
Store the contents of register R1 to the memory location addressed by
LOC1
Store src, dest Store R1, LOC1
Destination Source
Operand Operands
Add R2,R3,R4
R2 [R3] + [R4]
i Load R2,A
These memory locations
i+4 Load R3,B store the program
instructions.
i+8 Add R4,R2,R3
i + 12 Store R4, C R2 12
36
8
R3 12
36
8
A 12 R4 12
36
8
B 24 These memory locations
store the data values
C 10
36
222 used by the program.
Branch_if_[R2]>0 LOOP
If ([R2] > 0) then PC LOOP
Conditional branch
Condition: ([R2] > 0)
Branch target: LOOP
Branch_if_[R4]>[R5] LOOP
Branch_greater_than R4,R5,LOOP
Mnemonic
BGT R4,R5,LOOP
The program exits the loop when the count value in register
R2 is 0
Addressing modes
Different ways for specifying the locations of instruction operands
R1 1000
1000 20
NOTE:
In this case, R1 contains the address of one of the operands to be used in the
calculation. Indirect addressing is similar to dereferencing a pointer.
SUM
New Instruction
N
Move R4,#NUM1 Data values in memory
NUM1
Semantics: R4 NUM1 NUM2
1000 12
1020 36
N n Move R2,#LIST
Clear R3
LIST Student ID Clear R4
LIST + 4 Test 1 Student
Clear R5
LIST + 8 Test 2 Record 1 Load R6,N
LOOP: Load R7,4(R2)
LIST + 12 Test 3 Add R3,R3,R7
Student ID Load R7,8(R2)
Student Add R4,R4,R7
Test 1
Record 2 Load R7,12(R2)
Test 2 Add R5,R5,R7
Test 3 Add R2,R2,#16
Subtract R6,R6,#1
Branch_if_[R6]>0 LOOP
Student Store R3,SUM1
Record 3
Store R4,SUM2
Store R5,SUM3
NOTE:
SUM
The assembler calculates a relative
N address for a branch automatically when
NUM1 given a label for the start of the loop. J
NUM2
17
739
Stack
Pop
17
739
Stack
R2 100
High Memory Addresses
-28
17
Stack
739
R2 100
High Memory Addresses
Potential problem
Link register contents after SUB1 call are overwritten after second SUB2
call
Solution
SUB1 should save the address in the link register on the stack
before second call to SUB2
Before returning from SUB1, SUB1 should restore the contents of link
register
Subroutine
LISTADD: Subtract SP,SP,#4 Push [R5] on stack. Because its
Store R5,(SP) used in LISTADD
Clear R3
LOOP: Load R5,(R4)
Add R3,R3,R5
Add R4,R4,#4 Summation in a LOOP as before
NOTE:
Subtract R2,R2,#1
Can you identify
Branch_if_[R2]>0 LOOP
pass by reference
and pass by value Load R5,(SP) Restore [R5] in preparation to
in this example? Add SP,SP,#4 Return
Return
NOTE:
This is a complex stack frame that illustrates the use of parameter passing,
creation of a frame pointer, allocation of local variables, and the saving of
registers R2, R3, and R4 prior to modification.
Logic instructions
AND, OR, and NOT operations
Using RISC-style instructions, all operands are in registers or specified as
immediate values:
Or R4, R2, R3
And R5, R6, #0xFF
16-bit immediate is zero-extended to 32 bits
Assembler
A program that converts to machine instructions
Addressing modes
Subroutines
Stacks
Parameter passing
Additional instructions