15.08.2013 Views

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

program of a computer (those that run, when the power is turned on and bootstrap the operating<br />

system) is still given in special memory (called the firmware) that keeps its state even when power<br />

is shut off. This is conceptually very similar to a bank of switches.<br />

Example Programs<br />

Example 448 Exchange the values of cells 0 and 1 in the data store<br />

P instruction comment<br />

0 LOAD 0 ACC : = P (0) = x<br />

1 STORE 2 P (2): = ACC = x<br />

2 LOAD 1 ACC : = P (1) = y<br />

3 STORE 0 P (0): = ACC = y<br />

4 LOAD 2 ACC : = P (2) = x<br />

5 STORE 1 P (1): = ACC = x<br />

Example 449 Let P (1) = a, P (2) = b, and P (3) = c, store a + b + c in data cell 4<br />

P instruction comment<br />

0 LOAD 1 ACC : = P (1) = a<br />

1 ADD 2 ACC : = ACC +P (2) = a + b<br />

2 ADD 3 ACC : = ACC +P (3) = a + b + c<br />

3 STORE 4 P (4): = ACC = a + b + c<br />

use LOADI i, ADDI i, SUBI i to set/increment/decrement ACC (impossible otherwise)<br />

c○: Michael Kohlhase 277<br />

So far, the problems we have been able to solve are quite simple. They had in common that we had<br />

to know the addresses of the memory cells we wanted to operate on at programming time, which<br />

is not very realistic. To alleviate this restriction, we will now introduce a new set of instructions,<br />

which allow to calculate with addresses.<br />

Index Registers<br />

Problem: Given P (0) = x and P (1) = y, how to we store y into cell x of the data store?<br />

(impossible, as we have only absolute addressing)<br />

Definition 450 (Idea) introduce more registers and register instructions<br />

(IN1, IN2 suffice)<br />

instruction effect P C comment<br />

LOADIN j i ACC : = P (INj +i) P C : = P C +1 relative load<br />

STOREIN j i P (INj +i): = ACC P C : = P C +1 relative store<br />

MOVE S T T : = S P C : = P C +1 move register S (source)<br />

to register T (target)<br />

Problem Solution:<br />

P instruction comment<br />

0 LOAD 0 ACC : = P (0) = x<br />

1 MOVE ACC IN1 IN1: = ACC = x<br />

2 LOAD 1 ACC : = P (1) = y<br />

3 STOREIN 1 0 P (x) = P (IN1 +0): = ACC = y<br />

c○: Michael Kohlhase 278<br />

Note that the LOADIN are not binary instructions, but that this is just a short notation for unary<br />

155

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!