Question: Arithmetic instructions in NASM The purpose of this assignment is to give you programming practice using Arithmetic instructions in NASM. You will also practice converting
Arithmetic instructions in NASM
The purpose of this assignment is to give you programming practice using Arithmetic instructions in NASM. You will also practice converting single digit values to ASCII, incorporating line breaks in text output, defining initialized data, and reserving uninitialized data. You will also hammer home fundamental tasks like displaying text, proper program exiting, and moving data between registers, memory, etc.
Steps:
Open the Online Assembler
Near the top of the source code file, use comments to place your name into the code for credit No name, no credit!
Make sure every line of code you write has comments to explain what you are doing!
Follow the specifications below to get full credit for the assignment. Any errors or warnings will result in zero points for the code line in question:
SPECIFICATIONS
For this assignment, you are expected to do the following before we get to the text section:
Reserve a single byte of uninitialized data called "quo" to hold our quotient
Reserve a single byte of uninitialized data called "mod" to hold our remainder
Define a single byte of initialized data called "lbreak" to hold our line break character
Next, follow the steps below under the start: label to successfully complete the assignment:
Place a value of into the ax register
Add to this value using the "add" instruction
Subtract from this value using "sub" instruction
Place a value of into the bx register
Multiply bx by ax using the "mul" instruction
Place a value of into the cx register
Divide ax by the cx register using the "div" instruction
Convert the register with the quotient to ASCII
Transfer the ASCII value of the quotient to the "quo" memory address
Convert the register with the remainder modulo to ASCII
Transfer the ASCII value of the remainder to the "mod" memory address
Display the quo value
Display the line break character to break the line of text
Display the mod value
Do a proper system exit with normal exit code
Expected Output
If you did everything correctly, your output should be:
Two distinct values in different lines.
You should also have no errors or warnings.
This is an example:Let's look at an example program where we want to print two pieces of initialized data:
section data
n db ; This is our first number
n db ; This is our second number
lbreak db xA ; This is our line break character
section text
global start
start:
mov edx, ; # of bytes to write
mov ecx, n ; byte to write
mov ebx, ; stdout
mov eax, ; syswrite
int x ; system call
mov edx, ; # of bytes to write
mov ecx, n ; write the second value
mov ebx,
mov eax,
int x
mov eax, ; sysexit
mov ebx, ; exit is normal
int x ; system call
If you run this code, you will notice that it prints our values but it squeezes them together into one larger value instead of two distinct values and We can fix this easily by using the following code in between the first system call and the start of the second system call:
mov edx, ; length of byte to write
mov ecx, lbreak ; write the line break character
mov ebx, ; stdout
mov eax, ; syswrite
int x ; system call
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
