# Computer Science 237 Computer Organization

### Williams College Fall 2006

Lecture 07: Lecture Title
Date: Lecture Date

#### Agenda

• Announcements
• A quick look at possible solutions from Lab 1
• Lab 2 continues
• Assembly translation of sample code Translation: shiftyproduct.c example. A few things about our assembler:
• register names are preceded by %
• comment line starts with |
1. Assign variables to registers.
2. Choose a size for integers (often `.w`)
3. When necessary, allocate temporaries.
4. Translate step-by-step.
5. Don't be tricky.
6. Don't optimize; you'll regret it later.
• Data and address register direct: `%d3`
• Notion of effective address: ultimate location of value in memory
• Address register indirect: `(%a3)` the effective address of the data is found in an address register; used for pointers
• Address register indirect with displacement: `4(%a6)` the effective address of the data is the contents of the register plus an offset; used for fields in a structure.
• Address register indirect with displacement and indexing: `4(%a4,%d1.w)` effective address is the address register plus the contents of the displacement register plus the displacement; useful for arrays
• Address register indirect with predecrement: `-(%a7)` that is `-(%sp)` Suppose you're manipulating data with n bytes (1=b,2=w,4=l) Then
1. the address register is decremented by n
• Address register indirect with postincrement: `(%a7)+` that is `(%sp)+` Suppose you're manipulating data with n bytes (1=b,2=w,4=l) Then
2. the address register is incremented by n
• Immediate: `#4` We've seen and used this. There is no effective address.
• Absolute: `0x4000`
• it's just a number
• the effective address is in the operand
Better know what you're doing. Danger:
1. don't look at low addresses
• PC indirect with displacement: `4(%pc)` or `loop` (a label) this allows relocatable code - jumps are relative to PC.