gnu-assembler

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

Making a system call in GAS and using variables in .data section and accessing them for a system call inside another sub-routine

筅森魡賤 提交于 2020-08-10 20:47:27
问题 Here is the code example that I have written using GAS syntax for 64 bit intel assembly. When the code is run the expectation is to print out the string: Inside the _print subroutine. #This example is a an example to call a subroutine .global _start .section .text _start: call _print _exit: #exit call mov $60, %rax xor %rdi, %rdi syscall _print: #set up the stack frame push %rbp mov %rsp, %rbp # write syscall's parameter set up mov std_out_fd, %rdi mov $message, %rsi movq message_size, %rdx

Making a system call in GAS and using variables in .data section and accessing them for a system call inside another sub-routine

霸气de小男生 提交于 2020-08-10 20:43:26
问题 Here is the code example that I have written using GAS syntax for 64 bit intel assembly. When the code is run the expectation is to print out the string: Inside the _print subroutine. #This example is a an example to call a subroutine .global _start .section .text _start: call _print _exit: #exit call mov $60, %rax xor %rdi, %rdi syscall _print: #set up the stack frame push %rbp mov %rsp, %rbp # write syscall's parameter set up mov std_out_fd, %rdi mov $message, %rsi movq message_size, %rdx

How to use character literals in GNU GAS to replace numbers?

孤者浪人 提交于 2020-08-10 05:25:35
问题 For example, I'd like to write something like 'a' instead of 0x61 like I can in C. The manual mentions them at: https://sourceware.org/binutils/docs/as/Chars.html but without an example I'm not sure I understood. 回答1: /* Immediate. Without the `$`, does a memory access, and segfaults! */ mov $'a, %al /* al == 0x61 */ /* Memory. */ mov c, %al /* al == 0x62 */ c: .byte 'b /* Space character works. */ mov $' , %al /* al == 0x20 */ /* Backslash escapes work. */ mov $'\n , %al /* al == 0x0A */

Why IDIV with -1 causes floating point exception?

折月煮酒 提交于 2020-08-09 04:42:18
问题 As far as I understood, idiv %ebx will divide edx:eax (concatenated into 64-bit value, in that order) with 32-bit ebx . However, when I try to divide 0x00000000:0xfffffffb (0 and -5) with 0xffffffff (-1), I get a floating-point exception. Can someone explain why? I'm quite puzzled why this is happening because I'm not dividing by 0 after all. Note that I know I need to sign extend edx:eax to achieve what I want, which is to calculate -5/-1 . However, even without sign extension the below

Mixing C and Assembly. `Hello World` on 64-bit Linux

﹥>﹥吖頭↗ 提交于 2020-07-31 04:16:54
问题 Based on this tutorial, I am trying to write Hello World to the console on 64 bit Linux. Compilation raises no errors, but I get no text on console either. I don't know what is wrong. write.s : .data SYSREAD = 0 SYSWRITE = 1 SYSEXIT = 60 STDOUT = 1 STDIN = 0 EXIT_SUCCESS = 0 message: .ascii "Hello, world!\n" message_len = .-message .text .globl _write _write: pushq %rbp movq %rsp, %rbp movq $SYSWRITE, %rax movq $STDOUT, %rdi movq $message, %rsi movq $message_len, %rdx syscall popq %rbp ret

Mixing C and Assembly. `Hello World` on 64-bit Linux

自作多情 提交于 2020-07-31 04:16:50
问题 Based on this tutorial, I am trying to write Hello World to the console on 64 bit Linux. Compilation raises no errors, but I get no text on console either. I don't know what is wrong. write.s : .data SYSREAD = 0 SYSWRITE = 1 SYSEXIT = 60 STDOUT = 1 STDIN = 0 EXIT_SUCCESS = 0 message: .ascii "Hello, world!\n" message_len = .-message .text .globl _write _write: pushq %rbp movq %rsp, %rbp movq $SYSWRITE, %rax movq $STDOUT, %rdi movq $message, %rsi movq $message_len, %rdx syscall popq %rbp ret