4 Solved Problems on Computer Orange and Assembly Programming | CEG 320, Study notes of Computer Architecture and Organization

Material Type: Notes; Class: Computer Organization; Subject: Computer Engineering; University: Wright State University-Main Campus; Term: Fall 2004;

Typology: Study notes

Pre 2010

Uploaded on 08/19/2009

koofers-user-cjy
koofers-user-cjy 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1. Assembly to Pseudo-Code
Rewrite the following assembly routine into pseudo-code:
Solutions:
Option 1:
D0 = 10;
D0 = D0 - 2;
while (D0 >= 0) {
D1 = D1 + 1;
D0 = D0 - 2;
}
Option 2:
D0 = 10;
while (D0 - 2 >= 0) {
D1 = D1 + 1;
D0 = D0 - 2;
}
2. Pseudo-Code to Assembly
Rewrite the following pseudo-code into assembly code:
for ( i = 0; i < 7; i++ ) {
x = x + 2;
}
CEG 320/520: Computer Organization and Assembly Language Programming
Fall, 2004
In Class : Flow Control - General updated: 3-oct-04
1 ORG $001000
2 MOVE.L #10, D0
3 CLR.L D1
4 LOOP SUB.L #2, D0
5 BLT REST
6 ADD.W #1, D1
7 BRA LOOP
8REST END
pf3

Partial preview of the text

Download 4 Solved Problems on Computer Orange and Assembly Programming | CEG 320 and more Study notes Computer Architecture and Organization in PDF only on Docsity!

1. Assembly to Pseudo-Code

Rewrite the following assembly routine into pseudo-code:

Solutions:

Option 1: D0 = 10; D0 = D0 - 2; while (D0 >= 0) { D1 = D1 + 1; D0 = D0 - 2; }

Option 2: D0 = 10; while (D0 - 2 >= 0) { D1 = D1 + 1; D0 = D0 - 2; }

2. Pseudo-Code to Assembly

Rewrite the following pseudo-code into assembly code:

for ( i = 0; i < 7; i++ ) {

x = x + 2;

CEG 320/520: Computer Organization and Assembly Language Programming

Fall, 2004

In Class : Flow Control - General updated: 3-oct-

1 ORG $

2 MOVE.L #10, D

3 CLR.L D

4 LOOP SUB.L #2, D

5 BLT REST

6 ADD.W #1, D

7 BRA LOOP

8 REST END

3. The Condition Code Register and Branch Instructions

Consider these three instructions when answering the following three questions.

3a. What are the contents of D0 after the above instructions have been executed (decimal or hex)?

3b. The CMP instruction sets the N, Z, V, and C bits in the CCR. What are the values of those bits after

the following instruction (1/2 point per bit)?

Solutions:

Option 1 (total of 10 words in the loop): MOVE.W #0, D CLR.L D LOOP CMP #7, D BGE ENDLOOP ADD #2, D ADD #1, D BRA LOOP ENDLOOP NOP

Option 2 (total of 6 words in the loop): MOVE.W #7, D CLR.L D LOOP BLE ENDLOOP ADDQ #2, D SUBQ #1, D BRA LOOP ENDLOOP NOP

Option 3 (total of 4 words in the loop): MOVE.W #7, D CLR.L D LOOP ADDQ #2, D SUBQ #1, D BGT LOOP ENDLOOP NOP

1 CLR.L D

2 TARGET ADDQ.L #6, D

3 CMP.L #8, D

D0: $0000 0006

N Z V C