Sale!

CS2208b Assignment 4 solved

Original price was: $35.00.Current price is: $30.00. $25.50

Category:

Description

5/5 - (2 votes)

Strings

A string is an array representing a sequence of characters. To store a string of n characters in your program, you need to
set aside n+1 bytes of memory. This area of memory will contain the characters in the string, plus one extra special
character—the null character—to mark the end of the string. The null character is a byte whose bits are all zeros (0x00).
The actual string consists of any group of characters, which none of them can be the null character.

QUESTION 1 (25 marks)

Draw a detailed flowchart and write an ARM assembly language program to concatenate two stings (STRING1 and
STRING2) and store the result in a null terminated STRING3. Assume that the length of STRING1 + the length of
STRING2 ≤ 255.
Your code should be highly optimized, i.e., use as little number of instructions as possible.
You may want to define the strings as follow:
STRING1 DCB “This is a test string1” ;String1
EoS1 DCB 0x00 ;end of string1
STRING2 DCB “This is a test string2” ;String
EoS2 DCB 0x00 ;end of string2
STRING3 space 0xFF
CS2208b

QUESTION 2 (35 marks)

Draw a detailed flowchart and write an ARM assembly language program to copy a null terminated STRING1 to a null
terminated STRING2, after removing any occurrences of the word “the” in STRING1. I.e., if STRING1 is
“the woman and The man said the” then STRING2 would become “ woman and The man said ”.
However, if STRING1 is “and they took breathe” then STRING2 would become
“and they took breathe” without any change.
Your code should be highly optimized, i.e., use as little number of instructions as possible.
You may want to define the strings as follow:
STRING1 DCB “and the man said they must go” ;String1
EoS DCB 0x00 ;end of string1
STRING2 space 0xFF

QUESTION 3 (40 marks)

Draw a detailed flowchart and write an ARM assembly language function (subroutine) that takes a data value stored in
register r0 and returns a value in r0 as well. The function returns y = a × x2 + b × x + c where a, b, and c are signed
integer parameters built into the function (i.e., they are not passed to it) and are defined in the memory using three DCD
instructions.

The subroutine also performs clipping, i.e., if the output is greater than a value d, it is clipped to d, where d is
another parameter defined in the memory using a DCD instruction. The input in r0 is a signed integer binary value. Apart
from r0, no other registers may be modified by this subroutine, i.e., if you want to use any register as a working register,
you have to store its value in a safe place first prior changing it, and to restore this value before returning from the
function.

After implementing the function, write an assembly program which stores a value in r0 and calls your function. Once the
control is returned back from the function, the program will double the returned value and store this doubled value in r1.
Your code should be highly optimized, i.e., use as little number of instructions as possible.

Example1: if a = 5, b = 6, c = 7, d = 90, and r0 = 3,
then the returned value in r0 should be 70 and the value in r1 will be 140.
Example2: if a = 5, b = 6, c = 7, d = 50, and r0 = 3,
then the returned value in r0 should be 50 and the value in r1 will be 100.
Example3: if a = -5, b = 6, c = 7, d = 10, and r0 = 3,
then the returned value in r0 should be -20 and the value in r1 will be -40.
CS2208b Assignment 4