assembly

nasm system calls Linux

微笑、不失礼 提交于 2020-08-19 09:10:52
问题 I have got a question about linux x86 system calls in assembly. When I am creating a new assembly program with nasm on linux, I'd like to know which system calls I have to use for doing a specific task (for example reading a file, writing output, or simple exiting...). I know some syscall because I've read them on some examples taken around internet (such as eax=0, ebx=1 int 0x80 exit with return value of 1), but nothing more... How could I know if there are other arguments for exit syscall?

How to generate godbolt like clean assembly locally?

倖福魔咒の 提交于 2020-08-19 07:28:13
问题 I want to generate clean assembly like Compiler Explorer locally. Note that, I read How to remove “noise” from GCC/clang assembly output? before attempting this. The output using that method isn't as clean or dense compared to godbolt and still has a lot of asm directives and unused labels in it. How can I get clean assembly output without any unused labels or directives ? 回答1: A while ago, I needed something like this locally so I wrote a small tool to make the asm readable. It attempts to

Mixed destination/source operand order in RISC-V assembly syntax

[亡魂溺海] 提交于 2020-08-19 06:57:56
问题 Most instructions in RISC-V assembler order the destination operand before the source one, e.g.: li t0, 22 # destination, source li t1, 1 # destination, source add t2, t0, t1 # destination, source But the store instructions have that order reversed: sb t0, (sp) # source, destination lw t1, (a0) # destination, source vlb.v v4, (a1) # destination, source vsb.v v5, (a2) # source, destination How come? What is the motivation for this (arguably) asymmetric assembler syntax design? 回答1: I don't see

Assembly Linux system calls vs assembly OS x system calls

六眼飞鱼酱① 提交于 2020-08-19 04:57:45
问题 I have a problem with running assembly code on my mac. I am currently going through Jeff Duntemann's book Assembly Step by Step. The problem is that it focuses on writing assembly for 32 bit linux systems. I am using a 64 bit mac os x system. I can still run 32 bit assembly on my 64 bit system using nasm -f macho32, but apparently the code from Duntemann's book does not work because the system calls in Linux and mac os x are different. How would I convert this program: ; Executable name :

Assembly Linux system calls vs assembly OS x system calls

↘锁芯ラ 提交于 2020-08-19 04:56:12
问题 I have a problem with running assembly code on my mac. I am currently going through Jeff Duntemann's book Assembly Step by Step. The problem is that it focuses on writing assembly for 32 bit linux systems. I am using a 64 bit mac os x system. I can still run 32 bit assembly on my 64 bit system using nasm -f macho32, but apparently the code from Duntemann's book does not work because the system calls in Linux and mac os x are different. How would I convert this program: ; Executable name :

Commenting syntax for x86 AT&T syntax assembly

爷,独闯天下 提交于 2020-08-18 14:13:54
问题 The Intel syntax has comments using the semicolon. When I switched to AT&T, it actually tried to interpret the comments. What is the comment syntax for AT&T assembly? 回答1: Comments for at&t assembler are: # this is a comment /* this is a comment */ According to the fourth result Google gave me // and /* */ comments are only supported in .S files because GCC runs the C preprocessor on them before assembling. For .s files, the actual assembler itself ( as ) only handles # as a comment character

Commenting syntax for x86 AT&T syntax assembly

这一生的挚爱 提交于 2020-08-18 14:10:48
问题 The Intel syntax has comments using the semicolon. When I switched to AT&T, it actually tried to interpret the comments. What is the comment syntax for AT&T assembly? 回答1: Comments for at&t assembler are: # this is a comment /* this is a comment */ According to the fourth result Google gave me // and /* */ comments are only supported in .S files because GCC runs the C preprocessor on them before assembling. For .s files, the actual assembler itself ( as ) only handles # as a comment character

what does “mov offset(%rip), %rax” do?

冷暖自知 提交于 2020-08-18 06:51:40
问题 Does rax get offset plus the address of this instruction, or the next? From a microcode point of view it might be easier if the answer was the next instruction. 回答1: The next. That's a general rule on x86 (see also branches). In Intel's manual volume 2 section 2.2.1.6 RIP-Relative Addressing: A new addressing form, RIP-relative (relative instruction-pointer) addressing, is implemented in 64-bit mode. An effective address is formed by adding displacement to the 64-bit RIP of the next

Reading a single-key input on Linux (without waiting for return) using x86_64 sys_call

时光毁灭记忆、已成空白 提交于 2020-08-15 12:54:17
问题 I want to make linux just take 1 keystroke from keyboard using sys_read, but sys_read just wait until i pressed enter. How to read 1 keystroke ? this is my code: Mov EAX,3 Mov EBX,0 Mov ECX,Nada Mov EDX,1 Int 80h Cmp ECX,49 Je Do_C Jmp Error I already tried using BIOS interrupt but it's failed (Segmentation fault), I want capture number 1 to 8 input from keyboard. Thanks for the advance Sorry for bad english 回答1: Syscalls in 64-bit linux The tables from man syscall provide a good overview

Reading a single-key input on Linux (without waiting for return) using x86_64 sys_call

。_饼干妹妹 提交于 2020-08-15 12:53:55
问题 I want to make linux just take 1 keystroke from keyboard using sys_read, but sys_read just wait until i pressed enter. How to read 1 keystroke ? this is my code: Mov EAX,3 Mov EBX,0 Mov ECX,Nada Mov EDX,1 Int 80h Cmp ECX,49 Je Do_C Jmp Error I already tried using BIOS interrupt but it's failed (Segmentation fault), I want capture number 1 to 8 input from keyboard. Thanks for the advance Sorry for bad english 回答1: Syscalls in 64-bit linux The tables from man syscall provide a good overview