ECE 330 Homework 4 Spring 2011 Due: 2/16/2011

advertisement
ECE 330
Due: 2/16/2011
Homework 4
Spring 2011
1. Which routines require usage of the stack?
# a.s
.text
.global _start
_start:
...
call b
...
br
# b.s
.text
.global b
b:
...
call c
...
.
.end
ret
# c.s
.text
.global c
c:
...
# d.s
.text
.global d
d:
...
call d
call e
...
...
ret
ret
.end
.end
.end
2. Use the supplied assembly include file to answer the following questions.
# system.inc
.equ MEMORY_START,0x20000
.equ MEMORY_SIZE,131072
.equ STACK,MEMORY_START+MEMORY_SIZE
...
a. Provide code to initialize the stack.
b. Provide code to push registers r17,r19, r21 and ra onto the stack.
c. Provide code to pop the registers pushed in part b.
Page 1 of 4
# e.s
.text
.global e
e:
...
ret
.end
ECE 330
Due: 2/16/2011
Homework 4
Spring 2011
3. Use the following code snippets for the following questions.
# system.inc
.equ MEMORY_START,0x40000
.equ MEMORY_SIZE,131072
.equ STACK,MEMORY_START+MEMORY_SIZE
...
# a.s
# b.s
# c.s
# d.s
# e.s
.include “system.inc”
.text
.text
.text
.text
.text
b: .global b
c: .global c
d: .global d
e: .global e
_start: .globl _start
subi sp,sp,20
subi sp,sp,12
subi sp,sp,16
movia sp,STACK
...
...
...
...
call c
call d
call e
call b
...
...
...
addi sp,sp,20
addi sp,sp,12
addi sp,sp,16
ret
ret
ret
...
br
.end
.
.end
.end
.end
...
ret
.end
In the example above, assume that the current program counter is pointing to code in function e.
a. What are the byte addresses of stack space owned by function b?
b. What are the byte addresses of stack space owned by function c?
c. What are the byte addresses of stack space owned by function d?
d. What is the current value of the stack pointer (sp)?
Page 2 of 4
ECE 330
Due: 2/16/2011
Homework 4
Spring 2011
4. Create a function called strcpy with the following instructions.
For this problem, modify the configuration of Altera
Debug Client to start the data section at an offset of 100
(hex) as shown in Figure 1.
Using the following test code, create a new source
module strcpy.s that copies the string NAME to the TO
buffer. The string “NAME” is terminated by a zero
byte that can be used to identify the end of string.
Answer the following questions.
a. When you copy a string, do you copy the zero byte?
b. Explain the usage of the .word values of
0xbbbbbbbb, 0xeeeeeeee and 0xffffffff.
c. Why is the TO buffer defined as “40,1,0xa5”?
Figure 1.
Change the value of NAME to your name, compile and test your solution. When execution has
reached the break at PROGRAM_END, switch to the Memory tab in the Altera Debug Client. Right
click on page and select “Switch to character mode”. Then run the test with your strpcy
function.
Memory tab of Altera Debug Client
# file: test_strcpy.s
.text
_start:
.global _start
movia
sp, STACK
movia
movia
call
r5,NAME
r4,TO
strcpy
PROGRAM_END:
break
br
.data
NAME:
TO:
.end
PROGRAM_END
.word 0xbbbbbbbb
.string "your name here"
.fill 0x4,1,0xee
.word 0xaaaaaaaa
.fill 40,1,0xa5
.word 0xffffffff
Figure 2.
Following is a snapshot of memory before executing strcpy.
Supply a similar snapshot after executing strcpy that shows your name included in memory.
Provide code with homework.
Page 3 of 4
ECE 330
Due: 2/16/2011
Homework 4
Spring 2011
5. Using the following top level code, create a module sum.s that will compute the sum of
values passed. Note the setting up of registers before calling the function.
# test_sum.s
.include "system.inc"
.text
.global _start
_start:
movia
sp, STACK
movia
movia
ldw
call
r4,VALUES
r5,COUNT
r5,0(r5)
sum
# get count
movia
stw
r8,SUM
r2,0(r8)
# store SUM
mov
movia
call
r4,r2
r5,BUFF
itoh
# convert binary to printable
mov
r4,r5
# address of PBUFF
call
bsu_prints
br
.
# address of values array
# Halt execution
.data
COUNT:
SUM:
VALUES:
VALUES_END:
.word (VALUES_END-VALUES)/4
.word ~0
.word 3,2,7,9,4,11
BUFF:
.word 0,0,0,0,0
.fill 20,1,0xff
.end
Provide a screen shot of the JTAG UART console in Altera Debug Client that shows the
results.
Provide code with homework.
Page 4 of 4
Download