What addresses in memory contain array A?

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Machine organization

What addresses in memory contain array A?

 

### Translating a Java Program to LC3 Assembly Language

#### Java Program:
This simple Java program initializes an array `A` of size 10 with all elements set to 0. 
```java
for (i = 0; i < 10; i++) { 
    A[i] = 0; 
}
```

#### Corresponding LC3 Assembly Code:
The provided assembly code performs the same task as the Java program above, initializing 10 memory locations starting from a specific address with the value 0.

```assembly
.ORIG x3000       ; Set the starting memory address for the program
AND R0, R0, #0    ; Clear R0, i.e., set R0 to 0
AND R5, R5, #0    ; Clear R5, i.e., set R5 to 0
LD R1, ADDRA      ; Load the base address of the array into R1
LD R2, MINUS10    ; Load -10 into R2 for the loop comparison

LOOP:
ADD R3, R0, R2    ; R3 = R0 - 10, compare i < 10
BRz DONE          ; If i == 10, branch to DONE
ADD R4, R1, R0    ; Compute the address of A[i]
STR R5, R4, #0    ; Store 0 at A[i]
ADD R0, R0, #1    ; Increment i (R0)
BR LOOP           ; Repeat the loop

DONE:
HALT              ; End of the program

ADDRA .FILL x4000 ; Starting address of the array
MINUS10 .FILL #-10 ; Constant -10
.END              ; End of the assembly source file
```

### Detailed Explanation:

1. **Initialization and Clearing Registers:**
   - `.ORIG x3000`: The program starts at memory address `x3000`.
   - `AND R0, R0, #0`: Sets register `R0` to 0, representing the loop counter `i`.
   - `AND R5, R5, #0`: Sets register `R5` to 0, which will be stored in each element of the array.

2. **Loading Constants:**
   - `LD R1, ADDRA`: Loads the base address of the array into register `R1`.
Transcribed Image Text:### Translating a Java Program to LC3 Assembly Language #### Java Program: This simple Java program initializes an array `A` of size 10 with all elements set to 0. ```java for (i = 0; i < 10; i++) { A[i] = 0; } ``` #### Corresponding LC3 Assembly Code: The provided assembly code performs the same task as the Java program above, initializing 10 memory locations starting from a specific address with the value 0. ```assembly .ORIG x3000 ; Set the starting memory address for the program AND R0, R0, #0 ; Clear R0, i.e., set R0 to 0 AND R5, R5, #0 ; Clear R5, i.e., set R5 to 0 LD R1, ADDRA ; Load the base address of the array into R1 LD R2, MINUS10 ; Load -10 into R2 for the loop comparison LOOP: ADD R3, R0, R2 ; R3 = R0 - 10, compare i < 10 BRz DONE ; If i == 10, branch to DONE ADD R4, R1, R0 ; Compute the address of A[i] STR R5, R4, #0 ; Store 0 at A[i] ADD R0, R0, #1 ; Increment i (R0) BR LOOP ; Repeat the loop DONE: HALT ; End of the program ADDRA .FILL x4000 ; Starting address of the array MINUS10 .FILL #-10 ; Constant -10 .END ; End of the assembly source file ``` ### Detailed Explanation: 1. **Initialization and Clearing Registers:** - `.ORIG x3000`: The program starts at memory address `x3000`. - `AND R0, R0, #0`: Sets register `R0` to 0, representing the loop counter `i`. - `AND R5, R5, #0`: Sets register `R5` to 0, which will be stored in each element of the array. 2. **Loading Constants:** - `LD R1, ADDRA`: Loads the base address of the array into register `R1`.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY