CS计算机代考程序代写 database arm assembler algorithm assembly FP Format

FP Format
The FP format is similar (but not the same) to the one we studied in class. It has a sign bit, 4 bits of biased exponent, a bias value of 7 (base-10), and 4 bits of mantissa.
The following figure illustrates the bit assignments:
Points to note:
1. There is an implied ¡°1.¡± in front of the mantissa unless a denormal number.
2. Denormal numbers have ¡°0.¡± in front of the mantissa and an exponent field of 0000
which represents 2^-6.
3. Infinite numbers have an exponent field equal to 1111 with any value in the mantissa.
The following table shows how to interpret the exponent fields and matissa fields.
FP Format
sign (1)
exponent (4)
mantissa (4)
Exponent/mantissa
represents
Notes
1111/mmmm
2^8 x 1.mmmm
infinity
1110/mmmm
2^7 x 1.mmmm
normal number
1101/mmmm
2^6 x 1.mmmm
normal number
1100/mmmm
2^5 x 1.mmmm
normal number
1011/mmmm
2^4 x 1.mmmm
normal number
1010/mmmm
2^3 x 1.mmmm
normal number
1001/mmmm
2^2 x 1.mmmm
normal number
1000/mmmm
2^1 x 1.mmmm
normal number
0111/mmmm
2^0 x 1.mmmm
normal number
0110/mmmm
2^-1 x 1.mmmm
normal number
0101/mmmm
2^-2 x 1.mmmm
normal number
0100/mmmm
2^-3 x 1.mmmm
normal number
0011/mmmm
2^-4 x 1.mmmm
normal number

0010/mmmm
2^-5 x 1.mmmm
normal number
0001/mmmm
2^-6 x 1.mmmm
normal number
0000/mmmm
2^-6 x 0.mmmm
denormal number (no leading 0)
Number
Encoding in 9-bits
+0.0
9¡¯b0_0000_0000 (9bitsof0inbinary)
-0.0
9¡¯b1_0000_0000
Number
9-Bit Representation
Binary Representation
Base 10 Representation
Positive Infinity
9¡¯b0_1111_xxxx
+Inf
Negative Infinity
9¡¯b1_1111_xxxx
-Inf
Most Positive #
9¡¯b0_1110_1111
2^7 * 5¡¯b1.1111
8¡¯b11111000 =248
Smallest Positive #
9¡¯b0_0000_0001
2^-6 * 5¡¯b0.0001
1/1024 = 0.0009765625
MostNegative #
9¡¯b1_1110_1111
-2^7 * 5¡¯b1.1111
-9¡¯b111110000 = -248
Smallest Negative #
9¡¯b1_0000_0001
-2^-6 * 5¡¯b0.0001
– 1/1024 = -0.0009765625
IEEE-754 Single Precision Format
sign (1)
exponent (8)
mantissa (23)
The bias for the IEEE Format is 127 (base 10) and the format uses an implied 1 for normal numbers.The smallest representable exponent is -126 which is represented by 8¡¯b0000_0001 (normal numbers) and 8¡¯b0000_0000 (denormal numbers) . The exponent code – for IEEE Denorms 8¡¯b0000_0000 is not used by our program except for +-0, +0 is 32 bits of 0 and -0 is 1 followed by 31 0¡¯s. In IEEE single precision, any exponent of all 1¡¯s (0xff) represents a number too large to represent. For example 0xff80_0000 is a number with a negative sign bit,

all 1¡¯s for the exponent and all 0¡¯s for the mantissa. This represents negative Infinity (-Inf). Similarly, 0x7f80_0000 represents positive infinity (+Inf). Note that the mantissa bits are all 0. Non-zero mantissa bits represent another kind of IEEE special number (NaN – not a number) which is not used in this assignment.
Summary of Select Conversions (0¡¯s, min, max values)
FP
9-bit FP
IEEE-754 Single
+0
0_0000_0000
0x00000000
-0
1_0000_0000
0x80000000
0.0009765625
0_0000_0001
0x3a800000
-0.0009765625
1_0000_0001
0xba800000
248
0_1110_1111
0x43780000
-248
1_1110_1111
0xc3780000
+Inf
0_1111_xxxx
0x7f800000
-Inf
1_1111_xxxx
0xff800000
Your Mission
Your program will take a binary file name as an argument. Read in the file that is the argument passed to your program. This file is a raw binary file containing just bytes of data. For each 9 bits binary FP number in the file, decode those 9 bits, convert it into IEEE FP format and print it.
For example,
$ ./convertfp topsecret.bin
would read in the file topsecret.bin, convert each 9-bits to a floating point number, and print those numbers as decimal values to stdout. You can assume that a valid binary file is used and there won¡¯t be other arguments given.
[Developers tip: before you write assembly code, think about the algorithm. How are the 9 bit format and the 32-bit IEEE format similar and different? How does each field convert from our 9-bit format to the 32-bit IEEE format?]

Arguments
Arguments
Description
convertfp //
This is the executable
.bin
This .bin file contains binary information in the form of bytes of FP data. You will read this file one byte at a time, convert each number to IEEE FP format, and print it to the screen, one number per line.
Files and Methods You are provided 4 files:
1. fpconvert.S
2. Makefile (DO NOT EDIT)
3. main.c (DO NOT EDIT)
4. makebin.c (DO NOT EDIT: Described below under Testing)
1. main.c
This file is provided for you and already complete. DO NOT EDIT!
int main(int argc, char **argv)
Description
This file reads in the contents of the binary file, calls the below fpconvert routine, and prints the decoded 9-bit values to standard out. For each decoded 9 bit value from the binary input file, it will print the following three values on one line: the FP value in hex, the IEEE FP value in hex, and the decimal value.
2. fpconvert.s
This file contains two routines in ARM assembly that you will complete.
float fpconvert(unsigned int Num);

Description
Write a routine called fpconvert implemented in CSE 30 ARMv6 assembler (your routine is only allowed to use the cse30 subset of ARMv6).
fpconvert is called in the main method of main.c.
The routine fpconvert should convert all the non-infinity input cases – converting Num to an IEEE single precision float. If Exp is a 0xf as described above, it should call the routine convert_infinity (which is in the same file, described below).
Parameters
unsigned int Num
32-bit integer representation of an 9-bit FP number read from the input file (The value of the parameter is stored in R0 and you should store the return value in R0).
convert_infinity
Description
This routine should be called from within the assembly routine fpconvert if the n passed in to it has all exponent bits equal to 1 in the 9-bit FP form. The exponent bits in the IEEE form for such a number should now also be all 1s. (The value of the parameter is found in R0 and you should store the return value in R0). You shouldn’t need more than one other register in this function.
To call a function use the following instruction within fpconvert (bl is branch and link) bl convert_infinity // convert_infinity(r0)
//
At the end of the function, convert_infinity, there is an epilog, this will automatically return to the instruction after the bl.
Parameters
unsigned int n
32-bit integer representation of a 9-bit FP number read from the input file (This parameter should still be in register R0.)
Return value
Either a +Inf or -Inf value based on the sign of n. The return value is the last value of R0 before the function epilog (see starter code).

Development Process
To make development easier, you should first implement the conversion of normal numbers. First assume that the smallest positive and negative numbers1 in our 9-bit format are:
Test your code on a range of normal numbers (smallest, largest). Be sure to check the special cases of +0.0, -0.0 and +Inf and -Inf.
After thoroughly testing the functionality of your code you should consider denormal numbers. Denormal numbers are represented when the exponent field is 0. In this case the actual exponent will be 2^-6 and there will be a ¡°0.¡± in front of the mantissa. For example, the smallest positive number is represented by 9¡¯b0_0000_0001 which encodes the value 0.0001*2^-6m= 1/1024 = 0.0009765625
After implementing the conversion of denormal numbers your code should be able to produce all of the values in the Summary of Select Conversions table.
Getting Started
Instructions to Run Your Program
In order to run your program you MUST ssh into the pi-cluster on ieng6. Both your ieng6 and pi-cluster accounts share the same files so anything you copy to ieng6 (scp to ieng6) will ALSO be on the pi-cluster when you ssh in.
From Your Personal Computer
1. Open a Terminal
2. ssh into your ieng6 account
3. Download the starter code (see below).
4. ssh into the pi-cluster using the following command:
ex:
5. You are ready to start! (REMEMBER: when you exit, you need to do so twice if you want
to get back to your local machine!)
1 These are the smallest normal numbers.
FP
9-bit FP
IEEE-754 Single
0.015625
0_0001_0000
0x3c800000
-0.015625
1_0001_0000
0xbc800000
$ ssh @pi-cluster.ucsd.edu
$ ssh cs30sp21xx@pi-cluster.ucsd.edu

Running Your Program
We¡¯ve provided you with a Makefile and starter code. Additionally, we have placed the reference solution binary at:
/home/linux/ieng6/cs30sp21/public/bin/converfpA6_ref
Makefile: The Makefile provided will create a convertfp executable from the source files provided. Compile it by typing make into the terminal. Run make clean to remove files generated by make.
gdb: To run with gdb, the command is to start gdb with your executable. r [arguments] will run your executable with
Allowed Instructions
You are only allowed to use the instructions provided in the ARM ISA Green Card. Failure to comply will result in a score of 0 on the assignment.
Some Examples of types of instruction NOT ALLOWED in any CSE30 assignment: This is not an exhaustive list. For this assignment, you should not need to do any data transfer instructions.
gdb [executable]
[arguments]
example
description
comment
ldrb r0, [r4], #1
post indexed addressing
use only [register, #offset] or [register] addressing
ldr r0, [r4, r2]
double register indirect
use only [register, #offset] or [register] addressing
ldr r0, [r4, r2, lsl #2]
addressing with scaling
use only [register, #offset] or or [register] addressing
mov r6, r2, lsl #2
immediate with shift
use only simple immediates (no shift)
movgt
conditional move
do not use conditional instructions (only branches may be conditional)
bleq
conditional branch and link
use only bl

Testing
1. The file makebin.c has been provided so that you can easily create examples to test
your code on before submitting it to the headquarters¡¯ database.
Example contents of an input file (somehexnums.txt) given as an argument to makebin:
0x0
0x80
0x101
0x181
0x7f
0x1ff
Example on how to use makebin:
$ ./makebin somehexnums somehexnums.bin
Note: if you try to edit somehexnums.bin you will see a bunch of gibberish, as it’s a binary file.
Style Requirements
Points WILL be given for style, and teaching staff won’t be able to provide assistance or regrades unless code is readable. Please follow these Style Guidelines for ARM assembly.
Submission and Grading
Submitting
1. Submit your files to Gradescope under the assignment titled ¡°A6¡±. You will submit the following files :
¡ñ ¡ñ
To upload multiple files to gradescope, zip all of the files and upload the zip to
the assignment, or you can multi-select all files and drag and drop. Ensure that the files you submit are not in a nested folder.
2. After submitting, the autograder will run a few tests:
a. Checks that all required files were submitted
fpconvert.S
README

b. Checks that your source code compiles
c. Runs test input on your program and compares your output to ours
Grading Breakdown
Make sure to check the autograder output after submitting! We will be running additional tests after the deadline passes to determine your final grade.
You will receive 1 point for each test that you pass on Gradescope, and points for style. Make sure your assignment compiles correctly through the provided Makefile on the pi-cluster. Any assignment that does not compile will receive 0 credit. This assignment will also have 3 points dedicated to style (see above ARM assembly style requirements). We will be comparing the standard out of your program to ours, so please ensure nothing else is printed than what is printed by the provided main.
Slides and Video Slides
https://bit.ly/CSE30SP21A6Slides
Video
https://bit.ly/CSE30SP21A6Video