Question: PLEASE READ THE ASSIGNMENT CAREFULLY AND FOLLOW ALL INSTRUCTIONS. Bitwise instructions with keyboard input and ASCII output The purpose of this assignment is to give

PLEASE READ THE ASSIGNMENT CAREFULLY AND FOLLOW ALL INSTRUCTIONS.
Bitwise instructions with keyboard input and ASCII output
The purpose of this assignment is to give you combined practice with bitwise instructions, keyboard input, and console output all working together to form a cohesive small program.
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 1-byte of uninitialized data called "bite" to hold our second value for XOR
Reserve 1-byte of uninitialized data called "result" to hold our computation result (in ASCII form)
Description of functionality
Your program should assume 1-byte (value 6,7,8, or 9) being typed in the stdin box before running. Your program should retrieve this number and place it into the "bite" reference above.
Your program needs to convert this input digit into a raw value (not an ASCII character), XOR the value with 15, and place the result into the "result" piece of uninitialized data mentioned above. Be sure to add back the '0' ASCII code so it can be displayed.
Display the "result" to the console.
Make sure to properly exit the program (as always).
Expected Output
If you did everything correctly (assuming input of 9), your output should be:
6
You should also have no errors or warnings.
Caveat
!!!!!IMPORTANT!!!!!!!
USE ONLY NASM instructions: and, or, xor, shr, shl, mov, int, add, sub, mul, div. in the .text portion of the program. DONT USE OTHER INSTRUCTIONS.
Be aware that the digit will be in ASCII format coming from the keyboard. Therefore, we need to convert this input character to a number before doing calculations on it (bitwise or arithmetic). Here is an example:
section .bss
bite db 1 ; create a single-byte to hold input digit
result db 1 ; this will hold result of our computation eventually
section .text
global _start
_start:
mov eax, 3 ; sys_read
mov ebx, 0 ; stdin
mov ecx, bite ; input buffer
mov edx, 1 ; read 1-byte
int 0x80 ; system call
mov eax, [bite] ; transfer character to register
sub eax, '0' ; convert from ASCII to raw digit value
mov [bite], eax ; transfer back into input buffer
add eax, '0' ; convert result to ASCII
mov [result], eax ; transfer value to result
From here, we can easily output the result to console:
mov eax, 4 ; sys_write
mov ebx, 1 ; stdout
mov ecx, result ; output buffer
mov edx, 1 ; display 1-byte
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!