Question: Writing Loops ( FOR and WHILE loops ) Writing Decision statements ( IF statements ) Writing Functions Things you will need Virtualbox virtual machine (
Writing Loops FOR and WHILE loops
Writing Decision statements IF statements
Writing Functions
Things you will need
Virtualbox virtual machine with all the tools
A text editor provide by the VM VS code, Gedit, VIM,
The Nasm assembler provided by the VM
The ld linker provided by the VM
Description
For this assignment, you are going to write an assembler program that will test if sentences are palindromes. The highlevel pseudocode is as follows:
loop until the user is finished
prompt the user for a string
read a string from the keyboard
test the string to determine if it is a palindrome
if so then
print It is a palindrome"
else
print It is NOT a palindrome"
end loop
Your program will use the SYSREAD Linux call to read a sentence from the keyboard. The user will signify that they are finished by pressing without entering a sentence. After a call to SYSREAD in which the user presses without entering a string, the SYSREAD places a newline at the beginning of the buffer a newline byte contains the value So you should test after the call to SYSREAD, and if the first byte in the buffer is a newline, then your program should exit nicely by calling SYSEXIT
Also, you will implement a function called ispalindrome in assembler that your program will call to determine if a buffer contains a palindrome. The prototype for ispalindrome is as follows:
int ispalindromechar buffer int len;
The function returns a if the buffer contains a palindrome, or a if the buffer does not contain a palindrome. Note that the len that is passed should be the length of the string not counting the newline at the end that SYSREAD includes. Also, remember that SYSREAD returns the number of bytes read in EAX however do not forget to decrement EAX by so that you to not include the newline in the length To get credit for this assignment, you must follow all C calling conventions for a bit program on the Intel architecture what we have been studying in class for the ispalindrome function.
The program is to be written and tested on the virtual machine given in class, must compile using the nasm assembler, and must link using the ld linker. To compile the program, you will enter the following commands:
nasm g f elf F dwarf o palindrome.o palindrome.asm
ld palindrome.o m elfio palindrome
Do not use any macros or libraries for this assignment.
The following is a version of this program written in C that you can use as a reference. Your program should behave similarly to it
#include #include int ispalindromechar buf, int len; int main char buf; int count; write "Please enter a string:
; count read buf, ; while buf
count; if ispalindromebuf count writeIt is a palindrome
; else writeIt is NOT a palindrome
; write "Please enter a string:
; count read buf, ; return ; int ispalindromechar buf int len int i j; for i j len ; i len; i j if bufi bufj return ; return ;
The following shows an example run of this program:
$ palinc
Please enter a string:
It is a palindrome
Please enter a string:
rats live on no evil star
It is a palindrome
Please enter a string:
It is a palindrome
Please enter a string:
beef
It is NOT a palindrome
Please enter a string:
It is NOT a palindrome
Please enter a string:
$
The following command will compile the above example program written in C:
gcc g Wall o palinc palincc
Note: if you have gcc produce assembler from the C code and submit the gcc generated assembler, then the professor will know and give you a grade of write the program
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
