Homework, Assembly Language
REMARK
One is not allowed to use 128-bit registers XMM0 to XMM7!A library for long long unsigned integers
The goal of this work is to provide a library that implements very long unsigned integers (128-bit) in assembly language. You will also provide a program that tests the procedures from another file.The idea is to provide a library for working with very large unsigned numbers (we call them long long integers). You will provide procedures for all the basic functionalities expected for such elements. You have to write procedures for addition, multiplication, and subtraction. You also have to write two procedures for reading from the standard input and writing to the standard output a number in hexadecimal form.
Numbers are written in memory (on 16 bytes) using the "little endian" convention. The arguments for the procedures will always be the addresses of the numbers (the numbers are too large to be written in a register).
Work to be done
You need to provide a filemylongintlib.asm that is
written in Assembly language for 64 bit linux. This file will contain
the following features:
- A procedure
addition, that implements the addition of two long long integers. Input: the addresses of two long long numbers in RDI and RSI. Output: the result is written in the long long number at address in RDI. - A procedure
subtraction, that implements the subtraction of two long long integers. If the second number is larger than the first, the result is 0. Input: the addresses of two long long numbers in RDI and RSI. Output: the result is written in the long long number at address in RDI. - A procedure
multiplication, that implements the multiplication of two long long integers. Input: the addresses of two long long numbers in RDI and RSI. Output: the result is written in the long long number at address in RDI. If the size of the output should be larger than 128 bits, you will only use the 128-bits (lowest weight) and set the overflow flag (OF). - A procedure
readlonglongthat reads on the standard input (stdin) an hexadecimal number and writes it inside the memory. The inputRDIof the procedure contains the address in memory where to write the number. This procedure uses a 64-bitsyscall(not the C library). - A procedure
writelonglongwrites a long long number on the standard output in hexadecimal form. The input of the procedure is the value inRDI, it contains the address of the long long integer to be written. This procedure contains also a 64-bitsyscalland not the C library. - A procedure
copylonglongthat copies a long long number into another place in memory. This procedures receives as an inputRDIandRSI. InRDIyou have the address of the original number. InRSIyou have the address of the copy. You copy the original number into the copy.
global to be
accessed from another file.You also need to write a file containing a test program
testlonglong.asm. In this file
you need to declare the different procedures of your library as
extern in order to use them. You need to test your
library within your program. You have to implement the following
features. The outputs will be written using the C function
printf.
Your test program should do the following tasks:
- Reserve place in memory (BSS) for the following long long numbers (each time 128-bit numbers): X, Y, Z, R, S, T.
- Ask the user to enter a long long number X
- Ask the user to enter a long long number Y
- Ask the user to enter a long long number Z
- Copy X into a long long number R
- Copy Y into a long long number S
- Copy Z into a long long number T
- Do the following computations:
X = X + Y print X and Y X = X - Y print X and Y R = R - S print R and S T = T * Z print T and Z
Exercise
You have to write the two assembly language files: one for the library and one for testing the library.The output is written in the standard output (also like in all our exercises)
This exercise is to be done in a group of two students. If a class has an odd number of students, one student will work alone.
The program must be written in Assembly language, the only exception is the use of the C function
printf(), and maybe scanf(), inside the test
program (the functions are not allowed inside the library).
Deadline: 23rd of December 2016, the students must send to the professor a zip file containing a directory with the two assembly files and a makefile for compiling them.
Related Pages
Contact
Prof. Dr. Emmanuel Benoist
Berner Fachhochschule - TI
Quellgasse 21
CH-2501 Biel/Bienne
Switzerland
Mail: emmanuel.benoist (at) bfh.ch
Berner Fachhochschule - TI
Quellgasse 21
CH-2501 Biel/Bienne
Switzerland
Mail: emmanuel.benoist (at) bfh.ch
Social Networks
Follow
me
on
Linkedin, Scholar
& Research gate