# Computer Science 237 Computer Organization

### Williams College Fall 2005

Lecture 7: Assembly Programming, More Addressing Modes
Date: September 23, 2005

#### Announcements

• CS Colloquium today - more "What I did this summer" talks by CS students. 2:30 PM TCL 206.
• Turn in Lab 1 worksheets.
• Lab 2 Continues.

#### Agenda

• Assembly translation of sample code

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 demonstrate tricky translation.
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.

#### Practicalities

• A shell application is found in
/usr/cs-local/share/cs237/examples/shell.tar.gz
• Untar the file:
```    tar xvfz /usr/cs-local/share/cs237/examples/shell.tar.gz
```
• Rename the directory:
```    mv shell multiply
```
• Change to directory; edit main.s. (Default application draws a vertical line.)
• The debugger is invoked using BRK or DEB n directives.

Note you can see your registers.

BRK just stops the program

DEB n puts the value 0xDEB00000+n into D7 and stops

These are defined in the cs237.h file, a simpler way for you to get into the Palm debugger.

The values along the right are the contents of the stack - we'll worry about this later.

• Type make (also: make realclean)
• Start emulator & load application.
• Intricacies of running programs.

#### Examples

• multiply (the assembly version of shiftyproduct)