assembly

Linux x86-64 Hello World and register usage for parameters

若如初见. 提交于 2020-12-06 04:14:39
问题 I found this page which has a Hello World example for x86-64 on Linux: http://blog.markloiseau.com/2012/05/64-bit-hello-world-in-linux-assembly-nasm/ ; 64-bit "Hello World!" in Linux NASM global _start ; global entry point export for ld section .text _start: ; sys_write(stdout, message, length) mov rax, 1 ; sys_write mov rdi, 1 ; stdout mov rsi, message ; message address mov rdx, length ; message string length syscall ; sys_exit(return_code) mov rax, 60 ; sys_exit mov rdi, 0 ; return 0

Linux x86-64 Hello World and register usage for parameters

落花浮王杯 提交于 2020-12-06 04:14:29
问题 I found this page which has a Hello World example for x86-64 on Linux: http://blog.markloiseau.com/2012/05/64-bit-hello-world-in-linux-assembly-nasm/ ; 64-bit "Hello World!" in Linux NASM global _start ; global entry point export for ld section .text _start: ; sys_write(stdout, message, length) mov rax, 1 ; sys_write mov rdi, 1 ; stdout mov rsi, message ; message address mov rdx, length ; message string length syscall ; sys_exit(return_code) mov rax, 60 ; sys_exit mov rdi, 0 ; return 0

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

How do I interpet this x86_64 assembly opcode?

我的未来我决定 提交于 2020-12-02 05:55:51
问题 Looking at some assembly code for x86_64 on my Mac, I see the following instruction: 48 c7 c0 01 00 00 00 movq $0x1,%rax But nowhere can I find a reference that breaks down the opcode. It seems like 48c7 is a move instruction, c0 defines the %rax register, etc. So, where can I find a reference that tells me all that? I am aware of http://ref.x86asm.net/, but looking at 48 opcodes, I don't see anything that resembles a move. 回答1: Actually, mov is 0xc7 there; 0x48 is, in this case, a long mode

How do I interpet this x86_64 assembly opcode?

别来无恙 提交于 2020-12-02 05:55:26
问题 Looking at some assembly code for x86_64 on my Mac, I see the following instruction: 48 c7 c0 01 00 00 00 movq $0x1,%rax But nowhere can I find a reference that breaks down the opcode. It seems like 48c7 is a move instruction, c0 defines the %rax register, etc. So, where can I find a reference that tells me all that? I am aware of http://ref.x86asm.net/, but looking at 48 opcodes, I don't see anything that resembles a move. 回答1: Actually, mov is 0xc7 there; 0x48 is, in this case, a long mode

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,