Hi,
can someone show me a little program using mixed language, C and Assembly AT&T syntax.
I can't understand how it works .
Thanks
Hi,
can someone show me a little program using mixed language, C and Assembly AT&T syntax.
I can't understand how it works .
Thanks
You ended that sentence with a preposition...Bastard!
I suppose the first question is going to be "what's wrong with the 38,756 examples you can find on the web?"
But generally this is probably going to be rather system-specific, but if you're using gcc why not look at the HOWTO or the gcc manual?
Hey,
I will post some code I have.
Code:// mlpc1.c // C language source file for mixed language programming example #include <stdio.h> void UpperCase(char *Str); int main() { char UserString[20]; fputs("Enter a string: ",stdout); fgets(UserString,19,stdin); fputs("\nYou entered: ",stdout); fputs(UserString,stdout); fputs("\nAfter call to UpperCase this becomes: ",stdout); UpperCase(UserString); fputs(UserString,stdout); fputs("\n",stdout); }I don't get how it works...Code:# mpla1.s # assembly language source file for mixed language programming example .data .text .global UpperCase UpperCase: push %ebp mov %esp,%ebp push %esi push %eax mov 8(%ebp),%esi # make esi point to the string UCLoop: movb (%esi),%al cmp $0,%al je UCExit andb $0xdf,%al movb %al,(%esi) inc %esi jmp UCLoop UCExit: pop %eax pop %esi pop %ebp ret .end
You ended that sentence with a preposition...Bastard!
So what is difficult about this? This is exactly the same as you writing a C program in two .c files, except you wrote one of your .c files in assembler.
in the Uppercase function.
i don't get why the register
%esi or %eax was pushed
I have just written a simple function to add 2 numbers. And didn't have to push %eax. I could use them directly since they are "global", right?
So when do we push registers?
I know push means returning push a variable to the stack, but I don't really get a pop.
When you pop something off the stack, the esp is subtracted by 4 bytes.
but that content you popped off, is it saved somewhere? What is the difference between it and ret?
You ended that sentence with a preposition...Bastard!
Push stores a register value to the stack so that it can be restored later.
Pop gets the value from the stack and places it back in the register.
Of course you have to be careful with this... if you push A B C you need to pop C B A to restore the registers correctly. Also pushing something you do not later pop will cause a misalignment between stack and data...
so basically if it the data we have in the register is to be used later, we only push.
Ok, I will go try and do some experimenting on this.
Thanks.
You ended that sentence with a preposition...Bastard!
em, so
andb 0xdf, %cl
ands 223 with the lower case char.
How can we know what figure to use? Because if this was in the exam I would have failed it instantly. I just played with anding, and it does indeed convert it to upper.
if it was upper to lower, how would i do it? What would be my mask?
Is there an easy of figuring it out?
Thanks
You ended that sentence with a preposition...Bastard!
Code:Uppercase E = 69 = 0b01000101 Lowercase e = 101 = 0b01100101
so i have to or it by 0x20
E | 0x20..
that wouldn't work for everything
You ended that sentence with a preposition...Bastard!
Because if i had
Z 90 = 0b 0101 1010
z 122 = 0b 0010 0000
0b 0101 10101 | 0x20 would give me something else, not 122.
EDIT:
i think i made mistake in the calculation. brb
You ended that sentence with a preposition...Bastard!
90 is 0b01011010, true. 122, however, is 0b01111010, not 0b00100000 which is just 32.
Yeah it worked.
I am going to try the reverse, convert from lower to upper. I don't understand why we AND, and not OR.
You ended that sentence with a preposition...Bastard!