Step 1. Reverse a String \"Some University\" with the following requirements: -
ID: 3768936 • Letter: S
Question
Step 1. Reverse a String "Some University" with the following requirements: - Use a loop with indexed addressing - Push each character to the stack - Start at the beginning of the string, pop the stack in reverse order, insert each character back into the string -insert the following lines to display a string: mov edx, OFFSET call Writestring -insert the following line to generate a new line: call crlf ;new-line creater Prerequisite for Step 2: ReadString (from Irvine32 Library) The ReadString procedure reads a string from the keyboard, stopping when the user presses the Enter key. Pass the offset of a buffer in EDX and set ECX to the maximum number of characters the user can enter, plus 1 (to save space for the terminating null byte). The procedure returns the count of the number of characters typed by the user in EAX. Sample call: .data buffer BYTE 21 DUP(0) ; input buffer byteCount DWORD ? ; holds counter .code mov edx,OFFSET buffer ; point to the buffer mov ecx,SIZEOF buffer ; specify max characters call ReadString ; input the string mov byteCount,eax ; number of characters ReadString automatically inserts a null terminator in memory at the end of the string. The following is a hexadecimal and ASCII dump of the first 8 bytes of buffer after the user has entered the string “ABCDEFG”: 41 42 43 44 45 46 47 00 ABCDEFG The variable byteCount equals 7. Step 2: Extend Step1 to get a string from an user using ReadString procedure. Please comment out the declarations of variables used in Step1 rather than deleting them. Your output should be shown as below. Step 3: Write a program that does the following: Assigns integer values to EAX, EBX, ECX, EDX, ESI, EDI, EBP Use PUSHAD to push the general-purpose registers on the stack Using a loop, your program should pop each integer from the stack and display it on the screen Insert the following lines to display integers: WriteDec ; load a decimal value currently stored in EAX register crlf Your output for this step should be as follows except the fourth value. Specifically, you have to know the order in which registers are pushed onto the stack. Prerequisite for step 4: WriteDec (from Irvine32 Library) The WriteDec procedure writes a 32-bit unsigned integer to the console window in decimal format with no leading zeros. Pass the integer in EAX. Sample call: mov eax,295 call WriteDec ; displays: "295" Lastly Step 4 WriteDec (from Irvine32 Library) The WriteDec procedure writes a 32-bit unsigned integer to the console window in decimal format with no leading zeros. Pass the integer in EAX. Sample call: mov eax,295 call WriteDec ; displays: "295" All of this is in assembly language!
Explanation / Answer
Step 1:
#include <stdio.h>
#include <string.h>
#define max 100
int top,stack[max];
void push(char x){
//Inserting Element in stack
if(top==max-1){
printf("stack overflow");
} else {
stack[++top]=x;
}
}
void pop(){
// Removing element from stack
printf("%c",stack[top--]);
}
main()
{
char str[]="Some University";
int len = strlen(str),i;
for(i=0;i<len;i++)
push(str[i]);
for(i=0;i<len;i++)
pop();
}
Step 2:
section .text
global_start
_start:
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1
mov eax,4 ;system call number
int 0x80 ;call kernel
mov eax,1 ;system call number
int 0x80 ;call kernel
section .data
msg db 'Some University', 0xa
len equ $ - msg ;length
.data
buffer BYTE 21 DUP(0)
; input buffer
byteCount DWORD ?
; holds counter
.code
mov edx,OFFSET buffer
; point to the buffer
mov ecx,SIZEOF buffer
; specify max characters
call ReadString
; input the string
mov byteCount,eax ;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.