Part 2 (22 pts)
.ORIG x3000
LEA R1, STRZ
AND R2, R2, #0
LD R4, CHAR
REPEAT LDR R3, R1, #0
BRz FINISH ;Branch to FINISH if the value of R3 is
zero
ADD R3, R3, R4
BRnp PASS ;Branch to PASS if the value of R3 is
positive or negative
ADD R2, R2, #1
PASS ADD R1, R1, #1
BR REPEAT ;Branch always to REPEAT
FINISH ST R2, COUNT
HALT
CHAR .FILL xFF91
COUNT .FILL x0000
STRZ .STRINGZ "Hello world!"
.END
Attached you will find the code for this part in the file q2.asm.
Step 1: Download q2.asm and add it to the PennSim folder.
Step 2: Open the simulator and type the following instructions in the command line:
as lc3os.asm
load lc3os.obj
as q2.asm
load q2.obj
Step 3: Set PC to x3000.
Step 4: Run code and observe results.
Now answer the following questions:
Question 1: The ADDRESS and VALUE columns of the following table are snapshots of the assembler’s memory after you load the object file q2.obj. Fill in the CHARACTER column with the character each value represents. (6.5 pts)
ADDRESS |
VALUE |
CHARACTER |
x300E |
x0048 |
|
x300F |
x0065 |
|
x3010 |
x006C |
|
x3011 |
x006C |
|
x3012 |
x006F |
|
x3013 |
x0020 |
|
x3014 |
x0077 |
|
x3015 |
x006F |
|
x3016 |
x0072 |
|
x3017 |
x006C |
|
x3018 |
x0064 |
|
x3019 |
x0021 |
|
x301A |
x0000 |
Question 2: Fill in the symbol table created by the assembler after you load the object file q2.obj. (3 pts)
SYMBOL NAME |
MEMORY ADDRESS |
REPEAT |
|
PASS |
|
FINISH |
|
CHAR |
|
COUNT |
|
STRZ |
Question 3: How many times is the instruction at label “REPEAT” executed? (2 pts)
Question 4: How many times is the instruction at label “PASS” executed? (2 pts)
Question 5: What is the value of register R3 at the END of the 5th iteration? (2 pts)
Question 6: What is the value of register R3 at the END of the 8th iteration? (2 pts)
Question 7: Why did we set the value at label “CHAR” to xFF91? (Answer in one sentence only.) (2 pts)
Question 8: What is the final value of register R2 at the end of the execution? (0.5 pts)
Questions 9: Describe what this program does in one sentence only. (2 pts)
Question 1:
ADDRESS |
VALUE |
CHARACTER |
x300E |
x0048 |
|
x300F |
x0065 |
|
x3010 |
x006C |
|
x3011 |
x006C |
|
x3012 |
x006F |
|
x3013 |
x0020 |
|
x3014 |
x0077 |
|
x3015 |
x006F |
|
x3016 |
x0072 |
|
x3017 |
x006C |
|
x3018 |
x0064 |
|
x3019 |
x0021 |
|
x301A |
x0000 |
Question 2:
SYMBOL NAME |
MEMORY ADDRESS |
REPEAT |
3003 |
PASS |
3008 |
FINISH |
300A |
CHAR |
300C |
COUNT |
300D |
STRZ |
300E |
Question 3: Instruction at label "REPEAT" is executed 13 times
Question 4: Instruction at label “PASS” is executed 12 times
Question 5: The value of register R3 at the END of the 5th iteration is x0020
Question 6: The value of register R3 at the END of the 8th iteration is x0072
Question 7: To count the number of 'o' present in the string. (ASCII value of 'o' is decimal 111 and FF91 is decimal -111)
Question 8: The final value of register R2 at the end of the execution is 2
Questions 9: The program is iterating through the string "Hello world!"
Part 2 (22 pts) .ORIG x3000 LEA R1, STRZ AND R2, R2, #0 LD R4, CHAR...
; original codes provided as following .ORIG x3000 ; begin at x3000 ; input two numbers IN ; input an integer character (ascii) {TRAP 23} LD R3, HEXN30 ; subtract x30 to get integer ADD R0, R0, R3 ADD R1, R0, x0 ; move the first integer to register 1 IN ; input another integer {TRAP 23} ADD R0, R0, R3 ; convert it to an integer ; add the numbers ADD R2, R0, R1 ; add the two integers...
LC3 stack (factorial) I need help in writing factorial in Lc3 language by using stack.. ; Begin reserved section: do not change ANYTHING in reserved section! .ORIG x3000 BR Main ; Parameter and result Param .FILL x0004 Result .BLKW 1 ; Constants Stack .FILL x4000 One .FILL #1 MinusOne .FILL #-1 ; End reserved section: do not change ANYTHING in reserved section! ;------------------------------------------------------------------------------- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; int Factorial(int N) ; Returns N! (must be a recursive function) ; Factorial ;__________________...
2. a)Write the ARM ALP conditional code snippet for the following statements written in C-language. Assume R1 to Rn as06 variables Let R1, R2, R3 contain the starting addresses of arrays X, Y and Z respectively Use Register R4 for variable i. Display appropriate messages. While (i+10) else Z[i] XiYi; b)i Write a program to display a message "This is an examination Question" on the screen using 06 a function sub program Note the following Address of the string to...
The Fibonacci sequence F is defined as F(1) = F(2) = 1 and for n>= 2, F(n + 1) = F(n) + F(n − 1) i.e., the (n + 1)th value is given by the sum of the nth value and the (n − 1)th value. 1. Write an assembly program typical of RISC machines for computing the kth value F(k), where k is a natural number greater than 2 loaded from a memory location M, and storing the result...
1.) a.) Using the simplified instruction set shown for part b, write code for the following. Suppose memory locations 1400 to 1449 contain 16-bit words. Each word represents 2 ASCII characters. Write code to read in and write out these 100 characters. Left-side character from location 1400 should be first, right-side character from location 1400 should be second, and remaining characters follow in numeric order. Assume you have access to 4 registers: R1, R2, R3, R4. Each register holds one...
Note: The question needs to be answered in "C Programming Languange ". And after the question find 3 pages for needed informations. Spring CE4717 Language Processors Q1. Consider the following LEx program. return R1 return R2 return R3 return R4 return R5; return R6; IA-2a-z)[A-Za-z0-9]- -2 10-91+ 10-9a-EA-FI Ihi] [01] [01] 이삐 t Vtin) int main (void) int tcode; do f tcode -yylex()i printf ("token type td \"%s\"\n", tcode, yytext); ) while (tcode)i return 0; i. Explain the steps needed...