



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Assembly language homework problems for ece 332, including string copying, memory manipulation, and custom macro creation. It includes test code, memory snapshots, and instructions for compiling and testing solutions.
Typology: Exams
1 / 6
This page cannot be seen from the preview
Don't miss anything!




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. What should the values of r4 and r5 be when the strcpy function returns? c. Explain the usage of the .word values of 0xbbbbbbbb, 0xeeeeeeee and 0xffffffff. d. Why is the TO buffer defined as “40,1,0xa5”? 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.
Refer to the following link for more information on some of the dot directive in this code: http://www.gnu.org/software/binutils/manual/gas-2.9.1/html_mono/as.html
test_strcpy.s .text _start: .global _start br PROGRAM_START .org 0x
PROGRAM_START: break
movia r5,NAME movia r4,TO call strcpy
PROGRAM_END: break br PROGRAM_END
.data .word 0xbbbbbbbb NAME: .string "your name here" .word 0xeeeeeeee TO: .fill 40,1,0xa .word 0xffffffff .end
Memory tab of Altera Debug Client
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.
2. Repeat the process of Problem 1, but this time create the code to copy STR to TO with register r containing the number of bytes to copy.
test_memcpy.s .text _start: .global _start br PROGRAM_START .org 0x
PROGRAM_START: break
movi r6,STRLEN movia r5,STR movia r4,TO call memcpy
PROGRAM_END: break br PROGRAM_END
.data
.word 0xbbbbbbbb STR: .ascii "your name here" .equ STRLEN,.-STR .fill 4,1,0xee .word 0xaaaaaaaa TO: .fill 40,1,0xa .word 0xffffffff
.end
a. Explain how STRLEN is computed. (Hint: Search for the special dot symbol) b. Why do we use the .ascii directive here instead of .string or .asciz? c. Why is .fill 4,1,0xee used instead of the .word 0xeeeeeeee? d. What should the values of r4, r5 and r6 be after returning from memcpy routine?
Provide memory image of the .data region when memcpy has executed (same as Problem 1) and supply code for memcpy.s.
4. Create the following macros
setbit reg, index where reg is the register in which you wish to set a bit, and index is the register containing an index for the bit to be set
clearbit reg, index where reg is the register in which you wish to clear a bit, and index is the register containing an index for the bit to be cleared
getbit result, reg, index where result is the register to receive bit requested, reg is the register from which you wish to get a bit, and index is the register containing an index for the bit to be obtained
putbit reg, value, index where reg is the register in which you wish to put a bit, value is the register containing the bit to be put into reg, and index is the register containing an index for the bit to be put
5. Repeat Problem 4 but consider the index value to be an immediate instead of a register.
setbiti reg, index where reg is the register in which you wish to set a bit, and index is an immediate value specifying the index for the bit to be set
clearbiti reg, index where reg is the register in which you wish to clear a bit, and index is an immediate value specifying the index for the bit to be cleared
getbiti result, reg, index where result is the register to receive bit requested, reg is the register from which you wish to get a bitj, and index is an immediate value specifying the index for the bit to be obtained
putbiti reg, value, index where reg is the register in which you wish to put a bit, value is the register containing the bit to be put into reg, and index is an immediate value specifying the index for the bit to be put
6. Using the following test code, create a new source module itoa.s that converts the value in register r4 to an asciz string that represents the decimal value pointed to by the value in register r5. Then run the test with your itoa function.
test_itoa.s .include "../include/mymacros.s"
.text
_start: .global _start br PROGRAM_START
.org 0x
PROGRAM_START: movia sp,STACK /* Setup the stack and frame pointer / mov fp,sp / registers. */
break
movia r5,PBUFF movi r4, call itoa
mov r4,r call prints
break
PROGRAM_END: break br PROGRAM_END
.data
PBUFF: .fill 20,1,0xff
.end