Covert c program to assembly language program Compiler uses -S option to generate assembly language code for the given c source code. Below is the c source code(program.c). #include <stdio.h> int main() { int a, b, c; a = 20, b = 30; c = a + b; printf("Sum of two numbers is %d\n", c); return 0; } C source code can be converted to assembly code using the following command. jp@jp-VirtualBox:~/$ gcc -S program.c jp@jp-VirtualBox:~/$ ls program.c program.s Below is the assembly code for the above given c source code. .file "program.c" .section .rodata .LC0: ...
C programming code to reverse words in a string or sentence, For example if the input string is "c++ programming language" then the output will be "++c gnimmargorp egaugnal" i.e. we will invert each word occurring of the input string. Algorithm is very simple just scan the string and keep on storing characters until a space comes. If a space is found then we have found one word so we append null terminator and then reverse the word and then copy the characters of original string with the string obtained on reversing. Then repeat the previous step until the string ends. C programming code #include <stdio.h> #include <string.h> void reverse_string(char*); void reverse_words(char*); int main() { char a[100]; gets(a); reverse_words(a); printf("%s\n", a); return 0; } void reverse_words(char *s) { char b[100], *t, *z; int c = 0; t = s; while(*t) { ...
Far pointer: Size of the far pointer is 4 bytes and it can point to 1MB of memory. 4 bytes = 32 bits Far pointer has a 16 bit segment address and a 16 bit offset value. Below is the declaration for far pointer char far *ptr; Consider, a 32 bit address is stored in far pointer. char far *ptr = 0x82340005 Here, the 16 bit segment address is 0x8234 and offset value is 0x0005. So, below is the segment offset pair for 0x82340005 segment:offset = 0x8234:0x0005 Let us see how to convert segment offset pair to 20-bit physical address. Left shift the segment address by 4 bit = 0x8234 << 0x4 = 0x82340 Now, add the left shifted segment address and offset value to get 20 bit physical address. 20 bit physical address = (left shifted segment address)0x82340 + (offset)0x0005 ...
Comments
Post a Comment