gas

Is the hash required for immediate values in ARM assembly?

柔情痞子 提交于 2019-12-29 08:06:30
问题 I've been working on reading through some different arm assembly code generated by gcc, and I came across something that I haven't been able to find in the spec. movw r0, #39784 movt r0, 1 Obviously the first one is moving the value 39784 into the bottom 16bits or r0, but the movt's operand of '1' is odd because it doesnt have the hash before it, and I was under the impression that immediate values required the hash. Is it somehow optional in certain situations? or am I missing something

How to use RIP Relative Addressing in a 64-bit assembly program?

。_饼干妹妹 提交于 2019-12-27 14:42:24
问题 How do I use RIP Relative Addressing in a Linux assembly program for the AMD64 archtitecture? I am looking for a simple example (a Hello world program) that uses the AMD64 RIP relative adressing mode. For example the following 64-bit assembly program would work with normal (absolute addressing): .text .global _start _start: mov $0xd, %rdx mov $msg, %rsi pushq $0x1 pop %rax mov %rax, %rdi syscall xor %rdi, %rdi pushq $0x3c pop %rax syscall .data msg: .ascii "Hello world!\n" I am guessing that

Print register value to console

人盡茶涼 提交于 2019-12-26 21:39:49
问题 I want to print the value in %RCX directly to the console, let's say an ASCII value. I've searched through some wise books and tutorials, but all use buffers to pass anything. Is it possible to print anything without creating special buffer for that purpose? lets say i am here (all this answers are fat too complicated to me and use different syntax): movq $5, %rax ...???(print %rax) Output on console: \>5 in example, to print buffer i use code: SYSWRITE = 4 STDOUT = 1 EXIT_SUCCESS = 0 .text

How do you print a number stored in two registers (eg. EDX:EAX)?

旧街凉风 提交于 2019-12-25 07:55:17
问题 When you multiply two 32 bit numbers getting a 64 bit number stored in the registers EDX:EAX. How do you do to display the number in decimal form on the screen by only using system calls. Nothing from C. 来源: https://stackoverflow.com/questions/22584742/how-do-you-print-a-number-stored-in-two-registers-eg-edxeax

Initialize String Assembly

自古美人都是妖i 提交于 2019-12-25 05:34:32
问题 In i386 I'm trying to initialize a string in data. This is stupid, but I can't get it to work. sentence: .char 'h',0 says .char is an illegal pseudo op. Clearly I'm not doing it right, though sentence: db 'h',0 gives nothing either. 回答1: As lurker said, each assembler has its own syntax. db is used by nasm , for example. gas provides .byte , .string , .asciz and a bunch of other directives. See the manual. Your code could look like: sentence: .string "h" 来源: https://stackoverflow.com

NASM TO GAS: counterpart of resw in GAS

邮差的信 提交于 2019-12-24 16:58:27
问题 I am tasked to convert my assembly program which uses NASM to GAS. Unfortunately there are lots of mismatched statements. I have converted some of them but I am still having trouble on how to convert this statement min resw 1 回答1: You could try: .lcomm min, 2 or .comm min, 2 to put aside space for two bytes (one word) in the bss section. The point of the bss section is that the loader will allocate space and set the content to zero on load, but it won't take up space in your file on disk.

ASM call Printf

£可爱£侵袭症+ 提交于 2019-12-24 10:44:25
问题 movl %ebx, %esi movl $.LC1, %edi movl $0, %eax call printf I use the following asm code to print what is in EBX register. When I use movl $1,%eax int 0x80 and the echo $? I get the correct answer but segmentation fault in the first case. I am using the GNU Assembler and AT&T syntax. How can I fix this problem? 回答1: Judging by the code, you are probably in 64 bit mode (please confirm) in which case pointers are 64 bit in size. In a position-depended executable on Linux movl $.LC1, %edi is safe

Why does GCC produce ANDL $-16?

╄→尐↘猪︶ㄣ 提交于 2019-12-24 03:55:10
问题 I need some help understanding why GCC is doing main: pushl %ebp movl %esp, %ebp andl $-16, %esp # ??? subl $48, %esp # ??? movl $8, 16(%esp) movl $4, 20(%esp) Why does it first subtract 16 and then subtract 48 again? Wouldn't it be easier to do subl $64, %esp ? 回答1: andl $-16, %esp # ??? The above line is not subtracting 16 from esp but to align it to 16 byte boundary. While the following one is to subtract, mostly for reserving some space on the stack. subl $48, %esp # ??? 来源: https:/

How to get `mov rdx, symbol` to move symbol value and not value at symbol's address in clang intel-syntax?

◇◆丶佛笑我妖孽 提交于 2019-12-24 03:45:10
问题 I have the following code which I'm using with clang on macOS: .intel_syntax noprefix .data hello: .ascii "Hello world\n" hello_len = . - hello .text .globl _main _main: mov rax, 0x2000004 mov rdi, 1 lea rsi, [rip + hello] mov rdx, hello_len # <------- syscall mov rax, 0x2000001 syscall While it looks like it should print "Hello World" and exit, it actually segfaults. It turns out it's because mov rdx, hello_len actually tries to move the value that is at address hello_len , not the value of

Getting command line parameters from an assembly program

岁酱吖の 提交于 2019-12-23 22:01:53
问题 Reading through the "Professional Assembly Language Book"; it seems that it provides an erroneous code for reading command-line arguments. I corrected it a bit and now it went from segfaulting to reading argument count then segfaulting. Here's the full code: .data output1: .asciz "There are %d params:\n" output2: .asciz "%s\n" .text .globl main main: movl 4(%esp), %ecx /* Get argument count. */ pushl %ecx pushl $output1 call printf addl $4, %esp /* remove output1 */ /* ECX was corrupted by