att

gcc inline assembly behave strangely

主宰稳场 提交于 2021-02-19 08:25:11
问题 I am learning GCC's extended inline assembly currently. I wrote an A + B function and wants to detect the ZF flag, but things behave strangely. The compiler I use is gcc 7.3.1 on x86-64 Arch Linux. I started from the following code, this code will correctly print the a + b . int a, b, sum; scanf("%d%d", &a, &b); asm volatile ( "movl %1, %0\n" "addl %2, %0\n" : "=r"(sum) : "r"(a), "r"(b) : "cc" ); printf("%d\n", sum); Then I simply added a variable to check flags, it gives me wrong output. int

Chosing suffix (l-b-w) for mov instruction

痞子三分冷 提交于 2021-02-18 23:03:23
问题 I am new to assembly.I am reading computers system programmer's perspective. I don't understand how I choose suffix for mov instruction. I know each register and bit count. Suffix usage is determined by bit count (32 bit l , 16 bit w , 8 bit b ). Few example is not valid for prior sentence. For example %esp is 32-bit register but for 4. step suffix b is used instead of l . Please give an explanation for using suffix. questions : answer : l-w-b-b-l-w-l Source: Computer Systems: A Programmer's

Chosing suffix (l-b-w) for mov instruction

帅比萌擦擦* 提交于 2021-02-18 23:01:08
问题 I am new to assembly.I am reading computers system programmer's perspective. I don't understand how I choose suffix for mov instruction. I know each register and bit count. Suffix usage is determined by bit count (32 bit l , 16 bit w , 8 bit b ). Few example is not valid for prior sentence. For example %esp is 32-bit register but for 4. step suffix b is used instead of l . Please give an explanation for using suffix. questions : answer : l-w-b-b-l-w-l Source: Computer Systems: A Programmer's

Newton - Raphson inversion algorithm in assembly

纵饮孤独 提交于 2021-02-17 05:44:29
问题 I am trying to implement Newton - Raphson inversion algotihm in assembly according to this equation: Xn+1 = Xn(2-b*Xn) My function is: .data const: .int 2 .text .global inversion inversion: pushl %ebp movl %esp, %ebp fldl 8(%ebp) # load b fldl 12(%ebp) # load X0 inv: fst %st(2) # save Xn fmul %st(1), %st(0) # b*Xn fsubr const # 2-b*Xn fmul %st(2), %st(0) # Xn(2-b*Xn) fcomi %st(2), %st(0) # check if it the same result as before jne inv # jump # it should return the st(0) leave ret And my C

Using scanf into global or local variables (on the stack), 32-bit calling convention

好久不见. 提交于 2021-02-16 20:11:49
问题 Given the following code : .section .rodata str: .string "Hello World!\n" input: .long 2 ######## .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp pushl $str call printf #return from printf: movl $0, %eax movl %ebp,%esp popl %ebp ret The output would be "Hello World!". Now I try to get a number from the user , and then print it out on the screen , but it doesn't work (code compile,but I did something wrong) . Where is my mistake ? .section .rodata input: .long 2 ######

Using scanf into global or local variables (on the stack), 32-bit calling convention

邮差的信 提交于 2021-02-16 20:11:12
问题 Given the following code : .section .rodata str: .string "Hello World!\n" input: .long 2 ######## .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp pushl $str call printf #return from printf: movl $0, %eax movl %ebp,%esp popl %ebp ret The output would be "Hello World!". Now I try to get a number from the user , and then print it out on the screen , but it doesn't work (code compile,but I did something wrong) . Where is my mistake ? .section .rodata input: .long 2 ######

Assembler code, need help understand what 'movzwl 0x40272e(,%rax,4),%esi' is doing

▼魔方 西西 提交于 2021-02-10 17:29:22
问题 i understand what the other calls are doing but when i get line 36, i don't get what's happening? my 3 parameters are rsi = 5, rdx = 6, rcx = 7 On line 26 my %rax = 25 then on line 30 my rsi changes from 5 to 37 can you explain why this happens? and what is 0x40272e 0x0000000000401212 <+0>: sub $0x8,%rsp # subtract 8 from rsp 0x0000000000401216 <+4>: lea -0x1(%rdx),%rax # rax = -1 + rdx 0x000000000040121a <+8>: cmp $0xf,%rax # rax ?? 0xf '-1' 'SI' 0x000000000040121e <+12>: ja 0x40124f <phase

Moving a value of a lesser size into a register

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-05 11:38:22
问题 I have stored a one-byte value of 8 and I'd like to move that into the rax register. I'm currently doing this with movzx to zero-extend the byte: .globl main main: push %rbp mov %rsp, %rbp movb $8, -1(%rbp) movzx -1(%rbp), %rax <-- here ... How does the movzx instruction 'know' that the value at -1(%rbp) is only one byte long? From here is says, if I'm reading it properly, that it can work on both a byte and a word , but how would it know? For example, if I added a two-byte value at -2(%rbp)

Assembly infinite loop with printf function [duplicate]

六月ゝ 毕业季﹏ 提交于 2021-02-05 08:01:46
问题 This question already has answers here : What registers are preserved through a linux x86-64 function call (3 answers) Closed 6 months ago . can anyone explain why this code snippet goes into an infinite loop? I presume it would have something to do with the printf function. q1: .asciz "Hello World\n" .global main main: movq %rsp, %rbp movq $3, %rcx jmp bottom loop: movq $0, %rax movq $q1, %rdi call printf bottom: decq %rcx cmpq $0, %rcx jne loop end: movq $0, %rdi call exit 回答1: The only

What does AT&T syntax do about ambiguity between other mnemonics and operand-size suffixes?

谁说我不能喝 提交于 2021-02-05 07:12:05
问题 In AT&T syntax instructions often have to be suffixed with the appropriate operand size, with q for operations on 64-bit operands. However in MMX and SSE there is also movq instruction, with the q being in the original Intel mnemonic and not an additional suffix. So how will this be represented in AT&T? Is another q suffix needed like movqq %mm1, %mm0 movqq %xmm1, %xmm0 or not? And if there are any other instructions that end like AT&T suffixes (like paddd , slld ), do they work the same way?