Docsity

Analysis of a Given Assembly Program - Prof. James T. Sasaki, Assignments of Programming Languages

Toggle sidebar
bg1
Homework # 3 Solution v1.2 (10 pts/problem; 100 pts total)
6.07. (What does program (presented as binary core dump) do?)
!The program adds two lists of numbers element-wise. One list starts at address x300E
and the other starts at address x3013. The length of the two lists is at memory location
x3018. For n = 0, 1, ...., length-1., the n'th element of the first list (at x300E + n) is added
to the n'th element of the second list (at x3013 + n) and the result is stored back as the
n'th element of the first list.
6.08. (In example of Section 6.1.4, what happens if R2 ! 0 is omitted?)
!If we don't initialize R2, we don't know what's in it when we start executing. After
running, R2 would equal the difference between the number of occurrences and
whatever (unpredictable) initial value R2 happened to have.
6.12. (Write machine-level program to
!(a) echo a character
x3100 1111 0000 00100011 ; IN
x3101 1111 0000 00100001 ; OUT
x3102 0000 111 111111101 ; BRnzp x3100
!(b) echo a line
x3000 0010 001 000010001 ; LD r1, nl
x3001 1001 001 001 111111 ; NOT r1, r1
x3002 0001 001 001 1 00001 ; ADD r1, r1, #1
x3003 0010 010 000001111 ; LD r2, strg
x3004 1111 0000 00100011 ; iput IN
x3005 0111 000 010 000000 ; STR r0, r2, #0
x3006 0001 011 001 0 00 000 ; ADD r3, r1, r0
x3007 0000 010 000000010 ; BRz oput
x3008 0001 010 010 1 00001 ; ADD r2, r2, #1
x3009 0000 111 111111010 ; BRnzp iput
x300a 0010 010 0 0000 1000 ; oput LD r2, strg
x300b 0110 000 010 000000 ; oputl LDR r0, r2, #0
x300c 1111 0000 00100001 ; OUT
x300d 0001 011 001 0 00 000 ; ADD r3, r1, r0
x300e 0000 010 000000010 ; BRz done
x300f 0001 010 010 1 00001 ; ADD r2, r2, #1
x3010 0000 111 111111010 ; BRnzp oputl
x3011 1111 0000 00100101 ; done HALT
x3012 0000 0000 0000 1010 ; nl .FILL x0A
x3013 0100 0000 0000 0000 ; strg .FILL x4000
6.14. (Given core dump, what values in R1 cause R2 ! 3?)
!The possible values for R1 are: 9, 10, and 11.
6.15. (Given hex core dumps before and after execution, what instruction is at x3010?)
0111 010 100 000111 ; STR R2, R4, #7
CS 350: Comp Org & Assm Lang Pgmg!Spring'09!HW 3
J. Sasaki, CS Dept"Page 1 of 2"Illinois Institute of Technology
pf2

Partial preview of the text

Download Analysis of a Given Assembly Program - Prof. James T. Sasaki and more Assignments Programming Languages in PDF only on Docsity!

Homework # 3 Solution v1.2 (10 pts/problem; 100 pts total)

6.07. (What does program (presented as binary core dump) do?) ! The program adds two lists of numbers element-wise. One list starts at address x300E and the other starts at address x3013. The length of the two lists is at memory location x3018. For n = 0, 1, ...., length-1., the n'th element of the first list (at x300E + n) is added to the n'th element of the second list (at x3013 + n) and the result is stored back as the n'th element of the first list. 6.08. (In example of Section 6.1.4, what happens if R2! 0 is omitted?) ! If we don't initialize R2, we don't know what's in it when we start executing. After running, R2 would equal the difference between the number of occurrences and whatever (unpredictable) initial value R2 happened to have. 6.12. (Write machine-level program to ! (a) echo a character x3100 1111 0000 00100011 ; IN x3101 1111 0000 00100001 ; OUT x3102 0000 111 111111101 ; BRnzp x ! (b) echo a line x3000 0010 001 000010001 ; LD r1, nl x3001 1001 001 001 111111 ; NOT r1, r x3002 0001 001 001 1 00001 ; ADD r1, r1, # x3003 0010 010 000001111 ; LD r2, strg x3004 1111 0000 00100011 ; iput IN x3005 0111 000 010 000000 ; STR r0, r2, # x3006 0001 011 001 0 00 000 ; ADD r3, r1, r x3007 0000 010 000000010 ; BRz oput x3008 0001 010 010 1 00001 ; ADD r2, r2, # x3009 0000 111 111111010 ; BRnzp iput x300a 0010 010 0 0000 1000 ; oput LD r2, strg x300b 0110 000 010 000000 ; oputl LDR r0, r2, # x300c 1111 0000 00100001 ; OUT x300d 0001 011 001 0 00 000 ; ADD r3, r1, r x300e 0000 010 000000010 ; BRz done x300f 0001 010 010 1 00001 ; ADD r2, r2, # x3010 0000 111 111111010 ; BRnzp oputl x3011 1111 0000 00100101 ; done HALT x3012 0000 0000 0000 1010 ; nl .FILL x0A x3013 0100 0000 0000 0000 ; strg .FILL x 6.14. (Given core dump, what values in R1 cause R2! 3?) ! The possible values for R1 are: 9, 10, and 11. 6.15. (Given hex core dumps before and after execution, what instruction is at x3010?) 0111 010 100 000111 ; STR R2, R4, # CS 350: Comp Org & Assm Lang Pgmg! Spring'09! HW 3 J. Sasaki, CS Dept" Page 1 of 2 " Illinois Institute of Technology

7.02. (What does LABEL LD R1, LABEL do?) R1 will contain x23FF. Note because the instruction uses PC-offset addressing, it doesn't matter where in memory ASCII is stored; the offset will be -1. 7.04. (Create symbol table for given assembler program.) Test x301F Finish x Save3 x Save2 x302A 7.08. (Give register dump of program assembler program at breakpoint.) R0 xA R1 x23FF R2 xE1FF R3 xA R4 - R7 all x 7.16. (Given data in memory, how does following assembler program execute?) ! The program goes through the sequence of memory and keeps track of how many even and odd values it sees. R3 is set to the number of even values, R4 to the number of odd values. 7.18. (Given desired behavior, add 3 instructions to assembler program to complete it.) ! One possibility is (a) LDR R3,R1,# (b) NOT R3,R (c) ADD R3,R3,# ! Another is (a) LDR R3,R1,# (b) NOT R4,R (c) ADD R4,R4,# CS 350: Comp Org & Assm Lang Pgmg! Spring'09! HW 3 J. Sasaki, CS Dept" Page 2 of 2 " Illinois Institute of Technology