gas

Using scanf with x86-64 GAS assembly

旧巷老猫 提交于 2019-12-11 01:35:36
问题 I have been having loads of issues trying to get a call the the system function scanf to work in my x86 assembly program. Currently I have got it to read from standard in however, it only will read chars without a segfault (I have no idea why, the specifying string is %d). The examples I've seen of scanf in x86 online use quarky or are written with NASM syntax, thus I have tried to adapt them for my program. f: .string "%d" _main: movq $0, %rax #Clean rax movq $f, %rdi #Load string format

Interrupt On GAS

送分小仙女□ 提交于 2019-12-11 01:27:06
问题 I'm trying to convert my simple program from Intel syntax to the AT&T(to compile it with GAS). I've successfully converted a big part of my application, but I'm still getting an error with the int (the interrupts). My function is like this: printf: mov $0x0e, %ah mov $0x07, %bl nextchar: lodsb or %al, %al jz return int 10 jmp nextchar return: ret msg db "Welcome To Track!", 0Ah But when I compile it, I got this: hello.S: Assembler messages: hello.S:13: Error: operand size mismatch for int'

Meaning of .-main expression

允我心安 提交于 2019-12-11 01:25:44
问题 What does this expression mean: .-main in context of: .size main, .-main ? 回答1: Here, the dot . means "current location". Then .-main would be the distance to the start of main. If placed at the end of main, it would also be the size of main. 来源: https://stackoverflow.com/questions/11058361/meaning-of-main-expression

NASM to GAS: Calling equ'd symbols

一世执手 提交于 2019-12-10 18:16:46
问题 I have some NASM files which have a line: %INCLUDE "bmdev.asm" The bmdev.asm file has equ directives such as: b_print_newline equ 0x0000000000100040 The files which include bmdev.asm then are able to call those items. I.e. call b_print_newline Is there a way to convert this to GAS? When I try to do the direct translation, i.e. .set b_print_newline , 0x100040 call b_print_string it doesn't appear to disassemble to the right thing: callq *0x100040 The NASM call disassembles to: callq

how to export a function in GAS assembler?

柔情痞子 提交于 2019-12-10 11:30:02
问题 Hi I have the following assembly code , .export __ls__11NSDOM_EncapFf .text __ls__11NSDOM_EncapFf: /* first load the symbolic constant*/ movq _IEEE_FP@GOTPCREL(%rip), %r8 /*%r8 is a scratch register*/ movq (%r8), %r9 /* %r9 and %r11 are scratch registers*/ movl (%r9), %r11d /* second, see if it is zero and branch accordingly */ test %r11d, %r11d /* zero call TNS procedure */ /* non-zero call IEEE procedure */ je ____ls__11NSDOM_EncapFf_tns/* constant equals 0 */ jmp ____ls__11NSDOM_EncapFf

Why is this simple c program with gcc (clang) inline assembly exhibiting undefined behaviour?

帅比萌擦擦* 提交于 2019-12-10 11:28:58
问题 I'm trying to do a very simple thing with gcc assembler extension: load an unsigned int variable into a register add 1 to it output the result While compiling my solution: #include <stdio.h> #define inf_int volatile unsigned long long int main(int argc, char *argv[]){ inf_int zero = 0; inf_int one = 1; inf_int infinity = ~0; printf("value of zero, one, infinity = %llu, %llu, %llu\n", zero, one, infinity); __asm__ volatile ( "addq $1, %0" : "=r" (infinity) ); __asm__ volatile ( "addq $1, %0" :

WebRTC in iPhone (gas-preprocessor issues)

纵饮孤独 提交于 2019-12-08 11:42:37
问题 I'm trying compile the lastest WebRTC version for iPhone. I not need to compile the entire solution, I only need to compile the VAD module. To do that, I have created a Xcode project and I have tried to compile the source necessary, but I have a problem with the *.s files and its assembler. Like in the FFMPEG library, I know that I must "translate" the assembler code to an assembler code that the gcc for iPhone understand, but I don't know how I do this manually. I have tried to create a

GNU as, puts works but printf does not

空扰寡人 提交于 2019-12-08 09:29:02
问题 This is the code I am playing with right now: # file-name: test.s # 64-bit GNU as source code. .global main .section .text main: lea message, %rdi push %rdi call puts lea message, %rdi push %rdi call printf push $0 call _exit .section .data message: .asciz "Hello, World!" Compilation instructions: gcc test.s -o test Revision 1: .global main .section .text main: lea message, %rdi call puts lea message, %rdi call printf mov $0, %rdi call _exit .section .data message: .asciz "Hello, World!"

ARM/Thumb code for firmware patches…How to tell gcc assembler / linker to BL to absolute addr?

梦想与她 提交于 2019-12-08 02:43:13
问题 I'm trying to write a firmware mod (to existing firmware, for which i don't have source code) All Thumb code. does anybody have any idea how to do this, in gcc as (GAS) assembler: Use BL without having to manually calculate offsets, when BL 'ing to some existing function (not in my code.. but i know its address) Currently, if i want to use BL ...i have to : -go back in my code -figure out and add all the bytes that would result from assembling all the previous instructions in the function i'm

Calling C function from x64 assembly with registers instead of stack

筅森魡賤 提交于 2019-12-07 22:12:25
问题 This answer puzzled me. According to the standard C calling conventions, the standard way to call C functions is to push arguments to the stack and to call the subroutine. That is clearly different from syscalls, where you set different registers with appropriate arguments and then syscall . However, the answer mentioned above gives this GAS code: .global main .section .data hello: .asciz "Hello\n" .section .text main: movq $hello, %rdi movq $0, %rax call printf movq $0, %rax ret which works