Question

1 . Generate Assembly Codes for the two C programs below

a. Compare the assembly codes generated

b. For code B , analyze and explain how the function call “print_hello()” was materialized inside the computer (compiler, OS and the hardware) for the code B. Use figures and text descriptions if necessary

A)

#include <stdio.h void print hello0; int main(int argc, char *argv[]) print hello0; return 0; void print hello(){ printf(Hello, worldln);

B)

0 0
Add a comment Improve this question Transcribed image text
Answer #1
.model small                            ;defines the memory model to be used for the ALP
.data                                   ;data segment begins here
        msg db 10d,13d,"Hello World$"   ;String Hello World gets stored in msg

.code                                   ;code segment begins here
        mov ax,@data                    ;moving base address of data to ax
        mov ds,ax                       ;moving contents of ax into ds
                                        ;data section now gets initialized
        lea dx,msg                      ;load the offset address of msg
        mov ah,09h                      ;to display contents at dx
        int 21h                         ;call the kernel

        mov ah,4ch                      ;to terminate the program
        int 21h                         ;call the kernel
end

32 bit code

section .data                           ;.data starts here
        msg db 10d,"Hello World"        ;String gets initialized
        l equ $-msg                     ;Length Of String
section .text                           ;.text starts here
        global _start                   ;Moving to _start
_start:                                 ;_start label
        mov eax,4                      ;Sys_Write Function
        mov ebx,1                      ;Std_Out File Descriptor
        mov ecx,msg                    ;Offset of msg
        mov edx,l                      ;Length Of msg
        int 80h                                ;Call the Kernel

        mov eax,1                      ;Sys_Exit Function
        mov ebx,0                      ;Sucessful Termination
        int 80h                                ;Call The Kernel
end:                    
Add a comment
Know the answer?
Add Answer to:
1 . Generate Assembly Codes for the two C programs below a. Compare the assembly codes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Combine two codes (code 1) to get names with(code 2) to get info: Code 1: #include<unistd.h>...

    Combine two codes (code 1) to get names with(code 2) to get info: Code 1: #include<unistd.h> #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<dirent.h> #include<stdio.h> #include<stdlib.h> void do_ls(char []); int main(int argc,char *argv[]) { if(argc == 1) do_ls("."); else while(--argc){ printf("%s:\n",*++argv); do_ls(*argv); } } void do_ls(char dirname[]) { DIR *dir_ptr; struct dirent *direntp; if((dir_ptr = opendir(dirname)) == NULL) fprintf(stderr,"ls1:cannot open %s\n",dirname); else { while((direntp = readdir(dir_ptr)) != NULL) printf("%s\n",direntp->d_name); closedir(dir_ptr); } } ____________________________ code 2: #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> void show_stat_info(char *,...

  • OPERATING SYSTWM Question 31 What is the output of this C program? #include #include void main()...

    OPERATING SYSTWM Question 31 What is the output of this C program? #include #include void main() int mptr, *cptr mptr = (int*)malloc(sizeof(int)); printf("%d", "mptr); cptr = (int)calloc(sizeof(int),1); printf("%d","cptr); garbage 0 000 O garbage segmentation fault Question 8 1 pts If this program "Hello" is run from the command line as "Hello 12 3" what is the output? (char '1'is ascii value 49. char '2' is ascii value 50 char'3' is ascii value 51): #include<stdio.h> int main (int argc, char*argv[]) int...

  • PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int...

    PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int x, y; int h, w; } box; typedef struct { unsigned int baud : 5; unsigned int div2 : 1; unsigned int use_external_clock : 1; } flags; int main(int argc, char** argv){ printf("The size of box is %d bytes\n", sizeof(box)); printf("The size of flags is %d bytes\n", sizeof(flags)); return 0; } 2. #include <stdio.h> #include <string.h> /* define simple structure */ struct { unsigned...

  • Has to be in Unix! Lab 7 Programs 1. Create a prints.c file, and copy the...

    Has to be in Unix! Lab 7 Programs 1. Create a prints.c file, and copy the following into it: #include <stdio.h> int main(int argc, char * argv[]) { double x = 1.0, y = 5.1e7; float pi = 3.14159f; int i=0, j=5115; short int m= 6; unsigned long int n = 51151151; return 0; Now, write printf commands to: • print x with a field width of 6; print y with a field width of 8 and a precision of...

  • C programming Question1 (a) Write a C program that will print out all command line arguments,...

    C programming Question1 (a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index. 6 marks] (b) Consider this C code snippet int a- 100 int b- 42; inte p- &a; int q-b; p qi printf ("%d %d\n" ,a,*p); When this code is executed, what numbers will it print? [2 marks] (c) Consider this C program int main(int argc,char argv) char* target- "Apple" char vord[100] printf...

  • Write C programs named mystring.h and mystring.c, containing the headers and implementations of the following functions....

    Write C programs named mystring.h and mystring.c, containing the headers and implementations of the following functions. int letter_count(char *s) computes and returns the number of English letters in string s. int word_count(char *s) computes and returns the number of words in string s. void lower_case(char *s) changes upper case to lower case of string s. void trim(char *s) removes the unnecessary empty spaces of string s. mystring.h #include <stdio.h> int letter_count(char *); void lower_case(char *); int word_count(char *); void trim(char...

  • Writing a program in C please help!! My file worked fine before but when I put...

    Writing a program in C please help!! My file worked fine before but when I put the functions in their own files and made a header file the diplayadj() funtion no longer works properly. It will only print the vertices instead of both the vertices and the adjacent like below. example input form commnd line file: A B B C E X C D A C The directed edges in this example are: A can go to both B and...

  • Would u help me fixing this CODE With Debugging Code with GDB #include <stdio.h> #include <stdlib.h>...

    Would u help me fixing this CODE With Debugging Code with GDB #include <stdio.h> #include <stdlib.h> #define SIZE (10) typedef struct _debugLab { int i; char c; } debugLab; // Prototypes void PrintUsage(char *); void DebugOption1(void); void DebugOption2(void); int main(int argc, char **argv) { int option = 0; if (argc == 1) { PrintUsage(argv[0]); exit(0); } option = atoi(argv[1]); if (option == 1) { DebugOption1(); } else if (option == 2) { DebugOption2(); } else { PrintUsage(argv[0]); exit(0); } }...

  • Consider the following C codes to compute the gcd of two integers. /// code 1 #include...

    Consider the following C codes to compute the gcd of two integers. /// code 1 #include <stdio.h> int gcd(int a, int b) {     while (a != b) {         if (a > b) a = a - b;         else b = b - a;     }     return a; } /// code 2 #include <stdio.h> int getint() {     int i;     scanf("%d", &i);     return i; } void putint(int i) {     printf("%d\n", i); } int main()...

  • i want to fix the solution and provide an explanation why the pthread_join is not working...

    i want to fix the solution and provide an explanation why the pthread_join is not working as intended? #include <stdio.h> /* standard I/O routines */ #include <pthread.h> /* pthread functions and data structures */ void* PrintHello(void* data) { pthread_t tid = (pthread_t)data; /* data received by thread */ pthread_join(tid, NULL); /* wait for thread tid */ printf("Hello from new thread %u - got %u\n", pthread_self(), data); pthread_exit(NULL); /* terminate the thread */ } /* like any C program, program's execution...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT