Ense 352留学生讲解、讲解CS/python设计、辅导ASCII

- 首页 >> Python编程

Ense 352 – Fall 2018 – Assign 3

Handed Out: 2018-10-09

Due: 2018-10-17 by 23h55

1. (10 marks) Write a function in assembly language named int_to_ascii which

will extract the signed integer passed in R9 and convert it to a null-terminated

ASCII string representing the value of the integer in decimal. For example,

passing 0xc0010010 should create the ASCII string "-1073676272". Note the

following:

the input value is stored in binary, in a register. I’m only showing it in

hexadecimal for convenience, which is the only reason anyone ever uses

hexadecimal.

the output value does not include the double quotes.

the output value must be terminated with a null byte so it actually will

occupy 12 bytes.

Here are some more examples of correct conversions

input output actual hex bytes

34 " 34" 20 33 34 00

-34 "-34" 2d 33 34 00

0x34 " 52" 20 35 32 00

0x11111111 " 286331153" 20 32 38 36 33 33 31 31 35 33 00

You should insert a minus sign (-) if the input is negative, and leave a single

space otherwise.

You are required to allocate a sufficiently large RAM buffer to store the string

and its terminating null byte. The buffer must start at location 0x2000 0030.

Your function should return the address of the converted string in register R10.

2. (10 marks) Write a function in assembly language named encrypt which takes

a pointer to a buffer containing some cleartext, and modifies the buffer to contain

the encrypted version of that text.

The encryption scheme is to add a (wrap-around) displacement n to each alphabetic

char where the letters of the alphabet are numbered A=1, B=2, etc.

1

The same encoding is used for lower-case letters: a=1, b=2, etc. For example

given the clear text

AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz

0123456789

Hello, my boots are layered like an onion.

!@#$%^&*()_-+={}[]\|

<>,.?/~‘;:"’

and assuming for example n = 13, the result should be

NnOoPpQqRrSsTtUuVvWwXxYyZzAaBbCcDdEeFfGgHhIiJjKkLlMm

0123456789

Uryyb, zl obbgf ner ynlrerq yvxr na bavba.

!@#$%^&*()_-+={}[]\|

<>,.?/~‘;:"’

Note that only the alphabetic characters have changed, case has been preserved,

and each alphabetic character has been displaced by 13, for instance a Z being

character 26 becomes M (character 13), and a b (character 2) becomes o

(character 15).

Your code should accept any n from 0 to 25. Of course 0 means no change. If

a value larger than 25 is provided, your program should replace the contents of

the buffer with the string: XXXXX...XXX.

The buffer pointer must be stored in R4 while the buffer size and rotate amount

must be encoded in R3 as follows: size of the buffer must be stored in the bits

14:0 of R3, while the value of n must be stored in bits 19:15 of R3.

3. (5 marks) Write the complementary function decrypt which takes exactly the

same parameters as encrypt in the same format, and undoes what encrypt

did. Your decrypt should expect the same value of n to be passed as was

used originally in encrypt. So if you called encrypt with n = 6 you must call

decrypt also with n = 6 to decrypt that message. You should call encrypt as

part of this process.

Rules to follow

It’s important that you follow all the requirements stated for all the questions;

the marker will be testing the functions in q1, q2, and q2 by calling them from a

C/assembly testing framework. If your code does not adhere to the spec that will

cost significant marks.

Submit your solutions via urcourses in a single zipfile. Your submission will be rejected

if you don’t follow this. Place the solution to the questions in subfolders named

2

q1 and q23 (question 2 and 3 should be in the same project). You should only submit

assembly language source files, and an explanatory text file name 00readme.txt in

plain ASCII, which explains how your program works and any deficiencies in your

implementation. Your code should be written in standard cortex-m3 assembly language.


站长地图