Question

In: Computer Science

#include <stdio.h> #include <stdint.h> char sz_1[] = "Upper/LOWER."; char sz_2[] = "mIXeD CaSe.."; /* copies psz_2...

#include <stdio.h>
#include <stdint.h>

char sz_1[] = "Upper/LOWER.";
char sz_2[] = "mIXeD CaSe..";


/* copies psz_2 to psz_1, downcases all letters */
void dostr (char* psz_1,char* psz_2) {
uint8_t u8_c;

while (*psz_2 != 0) {
u8_c = *psz_2;
if (u8_c > 0x2F) {
/* make sure it is not a special char */
*psz_1 = u8_c | 0x20; /* sets this bit */
} else {
/* leave special chars alone */
*psz_1 = u8_c;
}
psz_1++;
psz_2++;
}

}

int main(void) {
// Bug: MPLAB X v1.80 printf bug means strings vis %s don't print correctly.
// So, break printf into two statements.
printf("Before...\n");
printf("sz_1: '"); printf(sz_1); printf("'\n");
printf("sz_2: '"); printf(sz_2); printf("'\n");
dostr(sz_1,sz_2);
printf("After...\n");
printf("sz_1: '"); printf(sz_1); printf("'\n");
printf("sz_2: '"); printf(sz_2); printf("'\n");
return 0;
}
convert it in assembly

Solutions

Expert Solution

Answer.

Step 1

ASSEMBLY LANGUAGE:

  • Assembly language is basically the low level language which is used for various kinds of processors for specific purposes.
  • For every high level language, when it is compiled it generates a low level code which is termed as assembly code.
  • As assembler is required to convert the assembly language code to the machine language code.
  • For different processor architecture, assembly language code is different while it consists of similar kinds of instruction and operations for various architecture.
  • Example of instructions that are used in assembly language are:
    • MOV - This instruction command is used to move the content from one location to other.
    • SUB - This instruction command is used to perform the subtraction operation
    • POP - This instruction command is used to take element from the stack
    • INT - This instruction command is used to interrupt any process

Step 2

CONVERTED ASSEMBLY CODE:

sz_1:   

        .string "Upper/LOWER."

sz_2:

        .string "mIXeD CaSe.."

dostr: // these block of statements defines the method signature

        push    rbp

        mov     rbp, rsp

        mov     QWORD PTR [rbp-24], rdi

        mov     QWORD PTR [rbp-32], rsi

        jmp     .L2 // start the while loop

.L5:

        mov     rax, QWORD PTR [rbp-32] // these statements are for assigning the pointer value

        movzx   eax, BYTE PTR [rax]

        mov     BYTE PTR [rbp-1], al

        cmp     BYTE PTR [rbp-1], 47 // statements for the if condition

        jbe     .L3

        movzx   eax, BYTE PTR [rbp-1] // statements for pointer assignments

        or      eax, 32

        mov     edx, eax

        mov     rax, QWORD PTR [rbp-24]

        mov     BYTE PTR [rax], dl

        jmp     .L4

.L3:

        movzx   edx, BYTE PTR [rbp-1] // again statements for pointer assignments

        mov     rax, QWORD PTR [rbp-24]

        mov     BYTE PTR [rax], dl

.L4:

        add     QWORD PTR [rbp-24], 1 // increment in pointer variable

        add     QWORD PTR [rbp-32], 1 // again increment in the pointer variable

.L2:

        mov     rax, QWORD PTR [rbp-32]

        movzx   eax, BYTE PTR [rax]

        test    al, al

        jne     .L5

        nop

        nop

        pop     rbp

        ret

.LC0:

        .string "Before..."

.LC1:

        .string "sz_1: '"

.LC2:

        .string "'"

.LC3:

        .string "sz_2: '"

.LC4:

        .string "After..."

main: // start the main function definition

        push    rbp

        mov     rbp, rsp

        mov     edi, OFFSET FLAT:.LC0 // printf statement conversion

        call    puts

        mov     edi, OFFSET FLAT:.LC1 // display the value using printf command

        mov     eax, 0

        call    printf

        mov     edi, OFFSET FLAT:sz_1

        mov     eax, 0

        call    printf

        mov     edi, OFFSET FLAT:.LC2

        call    puts

        mov     edi, OFFSET FLAT:.LC3 // command to display the value using printf

        mov     eax, 0

        call    printf

        mov     edi, OFFSET FLAT:sz_2   

        mov     eax, 0

        call    printf

        mov     edi, OFFSET FLAT:.LC2

        call    puts

        mov     esi, OFFSET FLAT:sz_2 // calls the function with the required parameters

        mov     edi, OFFSET FLAT:sz_1

        call    dostr

        mov     edi, OFFSET FLAT:.LC4 // print the space using printf command

        call    puts

        mov     edi, OFFSET FLAT:.LC1 // print the command using printf command

        mov     eax, 0

        call    printf

        mov     edi, OFFSET FLAT:sz_1

        mov     eax, 0

        call    printf

        mov     edi, OFFSET FLAT:.LC2

        call    puts

        mov     edi, OFFSET FLAT:.LC3 // display the values using the printf command

        mov     eax, 0

        call    printf

        mov     edi, OFFSET FLAT:sz_2

        mov     eax, 0

        call    printf

        mov     edi, OFFSET FLAT:.LC2

        call    puts

        mov     eax, 0 // return 0 command

        pop     rbp // closing curly braces

        ret

Kindly upvote please,

Thank you.


Related Solutions

Use the given Strings.c and Strings.h module: Strings.c: #include "Strings.h" #include <string.h> #include<stdlib.h> #include<stdio.h> char* substring(char*...
Use the given Strings.c and Strings.h module: Strings.c: #include "Strings.h" #include <string.h> #include<stdlib.h> #include<stdio.h> char* substring(char* str, int iPos){ if(iPos > strlen(str)||iPos < 0)return (char*)NULL; char* substr; substr = &str[iPos]; return substr; } int charPosition(char* str, char c){ char* string = (char*)malloc(strlen(str)+1); int i; for(i = 0; i < strlen(str)+1; i++) { if(str[i] == c) { return i; } } return -1; } Strings.h: #include <string.h> /* substring - return a pointer to the substring beginning at the iPos-th position....
Translate the following C program to Pep/9 assembly language: #include <stdio.h> char toLower(char ch) { if...
Translate the following C program to Pep/9 assembly language: #include <stdio.h> char toLower(char ch) { if (ch >= 'A' && ch <= 'Z' )        ch += 'a' - 'A'; return ch; } int main() { char ch, conversion; printf("Enter an uppercase letter: "); scanf("%c", &ch); conversion = toLower(ch); printf("\nLetter after conversion: %c\n\n", conversion); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(int argc, char *argv[]) {     FILE *myFile;...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(int argc, char *argv[]) {     FILE *myFile;     char fname[20];     //int sum = 0;     int i, j, k, tmp =0;     int num = 0;     int mass = 0;     int count = 0;     int fuel = 0;     int total = 0;     int M[1000];     char ch;     char buffer[32];     printf(" Input the filename to be opened : ");     scanf("%s",fname);     myFile = fopen(fname, "r");     if(myFile == NULL)     {         printf("Can't open file\n");     } while(1)     {         ch =...
#include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { int count; if ((argc...
#include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { int count; if ((argc != 2) || (sscanf(argv[1],"%d",&count) != 1)) { fprintf(stderr,"Usage: %s <integer>\n", argv[0]); exit(1); } pid_t pid1, pid2; while (count > 0) { pid1 = fork(); if (pid1 > 0) { pid2 = fork(); count = count - 2; } else if (pid1 == 0) { count = count - 1; } } exit(0); } Question #1 [2 pts] If the command-line argument passed to this...
*Answer in C program* #include <stdio.h> int main() {      FILE *fp1;      char c;     ...
*Answer in C program* #include <stdio.h> int main() {      FILE *fp1;      char c;      fp1= fopen ("C:\\myfiles\\newfile.txt", "r");      while(1)      {         c = fgetc(fp1);         if(c==EOF)             break;         else             printf("%c", c);      }      fclose(fp1);      return 0; } In the program above which statement is functioning for opening a file Write the syntax for opening a file What mode that being used in the program. Give the example from the program Referring to...
#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <sys/time.h> int main(int argc, char **argv) { pid_t pid;...
#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <sys/time.h> int main(int argc, char **argv) { pid_t pid; // Main process's PID=42 pid = fork(); // creates process with PID=36 if (pid == 0) { pid_t pid2 = fork(); // creates process with PID=99 sleep(10); if (pid2 > 0) { sleep(10); exit(0); } else { sleep(30); printf("** ONE **\n"); exit(0); } } else { pid_t pid3 = fork(); // creates process with PID=71 if (pid3 == 0) { sleep(30); exit(0); } pid_t...
#include <stdio.h> #include <string.h> #include<stdlib.h> #include<conio.h> struct Bank_Account_Holder { int account_no; char name[80]; int balance; };...
#include <stdio.h> #include <string.h> #include<stdlib.h> #include<conio.h> struct Bank_Account_Holder { int account_no; char name[80]; int balance; }; int n; void accept(struct Bank_Account_Holder[], int); void display(struct Bank_Account_Holder[], int); void save(struct Bank_Account_Holder[], int); void load(struct Bank_Account_Holder[], int); int search(struct Bank_Account_Holder[], int, int); void deposit(struct Bank_Account_Holder[], int, int, int); void withdraw(struct Bank_Account_Holder[], int, int, int); int lowBalenquiry(int,int); void main(void) { clrscr(); struct Bank_Account_Holder data[20]; int choice, account_no, amount, index; printf("NHU Banking System\n\n"); printf("Enter the count of records: "); scanf("%d", &n); accept(data, n); do {...
#include <stdio.h> int main() {      FILE *fp1;      char c;      fp1= fopen ("C:\\myfiles\\newfile.txt", "r");...
#include <stdio.h> int main() {      FILE *fp1;      char c;      fp1= fopen ("C:\\myfiles\\newfile.txt", "r");      while(1)      {         c = fgetc(fp1);         if(c==EOF)             break;         else             printf("%c", c);      }      fclose(fp1);      return 0; } In the program above which statement is functioning for opening a file Write the syntax for opening a file What mode that being used in the program. Give the example from the program Referring to the program above what...
#include <stdio.h> int main() {      FILE *fp1;      char c;      fp1= fopen ("C:\\myfiles\\newfile.txt", "r");...
#include <stdio.h> int main() {      FILE *fp1;      char c;      fp1= fopen ("C:\\myfiles\\newfile.txt", "r");      while(1)      {         c = fgetc(fp1);         if(c==EOF)             break;         else             printf("%c", c);      }      fclose(fp1);      return 0; } In the program above which statement is functioning for opening a file Write the syntax for opening a file What mode that being used in the program. Give the example from the program Referring to the program above what...
In a c programming Write a program that converts upper case letters to lower case letters...
In a c programming Write a program that converts upper case letters to lower case letters or vice versa: Enter a sentence: What a GREAT movie is! Converted sentence: wHAT_A_great_MOVIE_IS_ Convert all non-alphabetical letters to ‘_’
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT