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 2 into the ax register
Add 3 to this value using the "add" instruction
Subtract 1 from this value using "sub" instruction
Place a value of 2 into the bx register
Multiply bx by ax using the "mul" instruction
Place a value of 3 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:
2
2
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
n1 db '2' ; This is our first number
n2 db '3' ; This is our second number
lbreak db 0xA ; This is our line break character
section .text
global _start
_start:
mov edx, 1 ; # of bytes to write
mov ecx, n1 ; byte to write
mov ebx, 1 ; stdout
mov eax, 4 ; sys_write
int 0x80 ; system call
mov edx, 1 ; # of bytes to write
mov ecx, n2 ; write the second value
mov ebx, 1
mov eax, 4
int 0x80
mov eax, 1 ; sys_exit
mov ebx, 0 ; exit is normal
int 0x80 ; system call
If you run this code, you will notice that it prints our values but it squeezes them together into one larger value (23) instead of two distinct values (2 and 3). 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, 1 ; length of 1 byte to write
mov ecx, lbreak ; write the line break character
mov ebx, 1 ; stdout
mov eax, 4 ; sys_write
int 0x80 ; system call

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!