att

movq and 64 bit numbers

╄→尐↘猪︶ㄣ 提交于 2019-12-01 14:26:29
When I write to a register, everything is fine, movq $0xffffffffffffffff, %rax But I get Error: operand size mismatch when I write to a memory location, movq $0xffffffffffffffff, -8(%rbp) Why is that? I see in compiled C code that in asm these numbers are split in two and two movl instructions show up. Maybe you can tell me where the mowq and other instructions are documented. Why is that? Because MOV r64, imm64 is a valid x86 instruction, but MOV r/m64, imm64 is not (there's no encoding for it). I see in compiled C code that in asm these numbers are split in two and two movl instructions show

movq and 64 bit numbers

孤者浪人 提交于 2019-12-01 13:04:21
问题 When I write to a register, everything is fine, movq $0xffffffffffffffff, %rax But I get Error: operand size mismatch when I write to a memory location, movq $0xffffffffffffffff, -8(%rbp) Why is that? I see in compiled C code that in asm these numbers are split in two and two movl instructions show up. Maybe you can tell me where the mowq and other instructions are documented. 回答1: Why is that? Because MOV r64, imm64 is a valid x86 instruction, but MOV r/m64, imm64 is not (there's no encoding

c inline assembly getting “operand size mismatch” when using cmpxchg

六眼飞鱼酱① 提交于 2019-12-01 12:16:18
问题 I'm trying to use cmpxchg with inline assembly through c. This is my code: static inline int cas(volatile void* addr, int expected, int newval) { int ret; asm volatile("movl %2 , %%eax\n\t" "lock; cmpxchg %0, %3\n\t" "pushfl\n\t" "popl %1\n\t" "and $0x0040, %1\n\t" : "+m" (*(int*)addr), "=r" (ret) : "r" (expected), "r" (newval) : "%eax" ); return ret; } This is my first time using inline and i'm not sure what could be causing this problem. I tried "cmpxchgl" as well, but still nothing. Also

【leetcode】1222. Queens That Can Attack the King

╄→гoц情女王★ 提交于 2019-12-01 11:50:26
题目如下: On an 8x8 chessboard, there can be multiple Black Queens and one White King. Given an array of integer coordinates queens that represents the positions of the Black Queens, and a pair of coordinates king that represent the position of the White King, return the coordinates of all the queens (in any order) that can attack the King. Example 1: Input: queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0] Output: [[0,1],[1,0],[3,3]] Explanation: The queen at [0,1] can attack the king cause they're in the same row. The queen at [1,0] can attack the king cause they're in the same column

How to locate a variable correctly in AT&T assembly?

半腔热情 提交于 2019-12-01 06:05:34
I am practicing to write a bootstrap using assembly (in AT&T syntax, and gnu/gas). The small program is assembled and linked, then copied to the first sector of a virtual disk. BIOS will load it into 0000:7c00 , and here comes the problem. The call hello will be translated from call 0010 to call 7c10 during running. But the movw $message, %as doesn't get relocated. The ax is still 0026 , not 7c26 . The result is that I can't make the Hello World on the screen. Instead, some random data at 0000:0026 will be displayed on the screen. How can I make it correct during booting? Should I change the

mov instruction in x86 assembly

荒凉一梦 提交于 2019-12-01 03:10:25
From what I've read about mov , it copies the second argument into the first argument. Then, what does this do? movl 8(%ebp), %edx It copies whatever is in edx to the first parameter of the function (since an offset of +8 from ebp is a parameter)? I feel like what this really means is moving the first parameter into the edx register, but I read on Wikipedia that it is the other way around? movl 8(%ebp), %edx is in "AT&T Syntax"; in this syntax, the source comes first and the destination second. So yes, your belief is correct. Most documentation uses the "Intel Syntax", which has the reverse

What is callq instruction?

↘锁芯ラ 提交于 2019-12-01 02:43:41
I have some gnu assembler code for the x86_64 architecture generated by a tool and there are these instructions: movq %rsp, %rbp leaq str(%rip), %rdi callq puts movl $0, %eax I can not find actual documentation on the "callq" instruction. I have looked at http://support.amd.com/TechDocs/24594.pdf which is "AMD64 Architecture Programmer’s Manual Volume 3: General-Purpose and System Instructions" but they only describe CALL near and far instructions. I have looked at documentation for gnu assembler https://sourceware.org/binutils/docs/as/index.html but could not find the section detailing the

Trying to reverse engineer a function

我怕爱的太早我们不能终老 提交于 2019-12-01 00:22:25
I'm trying to understand assembly in x86 more. I have a mystery function here that I know returns an int and takes an int argument. So it looks like int mystery(int n){} . I can't figure out the function in C however. The assembly is: mov %edi, %eax lea 0x0(,%rdi, 8), %edi sub %eax, %edi add $0x4, %edi callq < mystery _util > repz retq < mystery _util > mov %edi, %eax shr %eax and $0x1, %edi and %edi, %eax retq I don't understand what the lea does here and what kind of function it could be. The assembly code appeared to be computer generated, and something that was probably compiled by GCC

Smart Bluetooth: GATT Vs. ATT - what are the differences between them?

好久不见. 提交于 2019-11-30 22:14:51
问题 Can anyone please define for me what are the differences between GATT and ATT? I didn't manage to understand. I know that they are both generic protocol to handle BLE services. but didn't really understand it. Please explain. Thanks! 回答1: ATT is a much lower level mechanism that basically defines how to transfer a unit of data (an attribute). GATT is built on top of ATT and defines how higher level services are composed and the framework for operating on those services. 回答2: You can find the

Why does switching from AT&T to Intel syntax make this tutorial segfault using GAS?

强颜欢笑 提交于 2019-11-30 13:04:35
I'm working through some of the tutorials on http://www.ibm.com/developerworks/linux/library/l-gas-nasm/index.html to familiarize myself with x86/x64. This tutorial code compiles and runs without a hiccup using the provided code, which uses AT&T syntax: .global main .text main: # This is called by C library's startup code mov $message, %rdi # First integer (or pointer) parameter in %edi call puts # puts("Hello, World") ret # Return to C library code message: .asciz "Hello, World" # asciz puts a 0x00 byte at the end However, when I convert this code to Intel syntax, I get a "Segmentation fault"