x86

where goes the ret instruction of the main

人盡茶涼 提交于 2020-12-05 11:55:48
问题 I learned how assembly (x86) globally works in the book : "Programming from ground up". In this book, every program ends with an interruption call to exit. However, in C compiled programs, I found out that programs end with a ret. This supposes that there is an address to be popped and that would lead to the end of the program. So my question is : What is this address? (And what is the code there?) 回答1: You start your program by asking the OS to pass control to the start or _start function of

Macro substituting a constant number in GAS

烈酒焚心 提交于 2020-12-05 04:58:25
问题 What't wrong with that macro on X86 GNU Assembly? It says the symbol S is undefined during linking. .macro S size=40 \size .endm I'm using it like mov %eax, S 回答1: Macros are used to create templates for code you frequently use, not to input a constant number. As such, I do not believe the assembler does macro expansion within an expression. Since you simply want a number, you could use .set to define a constant. .set S, 40 mov %eax, S Also, in case you usually use intel syntax, make sure you

How can I check if a character is a letter in assembly?

孤街浪徒 提交于 2020-12-04 12:01:28
问题 So, I have a block of code which sets the bounders to check if a character is a letter (not numbers, not symbols), but I don't think it works for the characters in between upper and lower case. Can you help? Thanks! mov al, byte ptr[esi + ecx]; move the first character to al cmp al, 0 ; compare al with null which is the end of string je done ; if yes, jump to done cmp al, 0x41 ; compare al with "A" (upper bounder) jl next_char ; jump to next character if less cmp al, 0x7A ; compare al with "z

How can I check if a character is a letter in assembly?

这一生的挚爱 提交于 2020-12-04 11:57:08
问题 So, I have a block of code which sets the bounders to check if a character is a letter (not numbers, not symbols), but I don't think it works for the characters in between upper and lower case. Can you help? Thanks! mov al, byte ptr[esi + ecx]; move the first character to al cmp al, 0 ; compare al with null which is the end of string je done ; if yes, jump to done cmp al, 0x41 ; compare al with "A" (upper bounder) jl next_char ; jump to next character if less cmp al, 0x7A ; compare al with "z

Does it matter which registers you use when writing assembly?

守給你的承諾、 提交于 2020-12-03 07:27:10
问题 If you're writing assembly, does it matter which registers you allocate values to? Say, you store an accumulated/intermediate value in %ebx instead of %eax, which was traditionally used for that purpose. Is that bad practice? Will it affect performance? In other words, can you treat them equally as storage space, or should you stick to using them for specific purposes? 回答1: First and foremost, you have to use registers that support the instructions you want to use. Many instructions on x86

Intel assembly syntax OFFSET

别说谁变了你拦得住时间么 提交于 2020-12-01 10:46:05
问题 Now that i know u can use gcc for Intel syntax instead of default at&t with gcc -S -masm=intel test.c There is this line mov DWORD PTR [ebp-16], OFFSET FLAT:base Is it the same as mov dword[ebp-16], base ? Otherwise what must i do? 回答1: Yes, mov dword [ebp - 16], base should be fine. I haven't seen offset flat: for a while - I think it's obsolete, but it's what AT&T's idea of .intel_syntax used to demand (I had to look at Gas's source code to find that out). Means the same as offset to Masm,

need help understanding the movzbl call in this function

我只是一个虾纸丫 提交于 2020-12-01 07:40:36
问题 So I'm trying to write some C code by looking at the assembly here: pushl %ebp movl %esp, %ebp movl 12(%ebp), %eax addl 8(%ebp), %eax movzbl (%eax), %eax movsbl %al,%eax popl %ebp ret I see that I have two variables, and they are being added together, then I'm getting lost when looking when the function starts calling movzbl and movesbl. What's going on here? 回答1: A corresponding C function would be something like char fn(char * string, int index) { return string[index]; } Specifically, the

need help understanding the movzbl call in this function

随声附和 提交于 2020-12-01 07:35:25
问题 So I'm trying to write some C code by looking at the assembly here: pushl %ebp movl %esp, %ebp movl 12(%ebp), %eax addl 8(%ebp), %eax movzbl (%eax), %eax movsbl %al,%eax popl %ebp ret I see that I have two variables, and they are being added together, then I'm getting lost when looking when the function starts calling movzbl and movesbl. What's going on here? 回答1: A corresponding C function would be something like char fn(char * string, int index) { return string[index]; } Specifically, the

need help understanding the movzbl call in this function

倾然丶 夕夏残阳落幕 提交于 2020-12-01 07:33:00
问题 So I'm trying to write some C code by looking at the assembly here: pushl %ebp movl %esp, %ebp movl 12(%ebp), %eax addl 8(%ebp), %eax movzbl (%eax), %eax movsbl %al,%eax popl %ebp ret I see that I have two variables, and they are being added together, then I'm getting lost when looking when the function starts calling movzbl and movesbl. What's going on here? 回答1: A corresponding C function would be something like char fn(char * string, int index) { return string[index]; } Specifically, the

x86 assembly extreme novice inquiry: “invalid instruction operands”?

岁酱吖の 提交于 2020-11-29 10:09:03
问题 The code below is only a small fraction of the program I am currently attempting to write, but no other parts of the program are relevant, so I only pasted what was necessary. Anyway, what I am trying to do is move the value stored within inputLoopCounter into ecx in order to determine how many times a loop should execute. However, when I attempt to assemble this program, I get the error mentioned in the question title. Can anybody explain the reason for this? .data inputLoopCounter BYTE -1