Giter VIP home page Giter VIP logo

Comments (3)

mattbucci avatar mattbucci commented on June 12, 2024

There's a few issues here:

  1. AT&T mov syntax is backwards, which is why we ended up flipping the variable order
  2. I don't think we can use the same m(variable) syntax we use in the other ASM format, I don't see mention of it in AT&T syntax.

all registers in AT&T syntax must be prefixed with "%", all literals must be prefixed with "$", dereferencing seems to be done by wrapping the register with "(" and ")" https://csiflabs.cs.ucdavis.edu/~ssdavis/50/att-syntax.htm

Our old definition was

#define ASM_MOV_REG_VAR(register, variable) \
    __asm__ __volatile__("mov %0, %%" EXPAND_AND_QUOTE(register)  : : "m"(variable) : )

I tried

__asm__ __volatile__("mov $" EXPAND_AND_QUOTE(variable) ", %" EXPAND_AND_QUOTE(register) )

but this results in "error: 32-bit absolute addressing is not supported in 64-bit mode"
$(variable) should grab the value held by the pointer and move it into the register if I understand correctly.

from squally.

mattbucci avatar mattbucci commented on June 12, 2024

@zcanann I'm not sure I understand what the %0 is doing here I understand it points to a stack variable, but yeah we're pretty far from having this right. Here's the example usage

Vec3 ProximityObject::getVelocity()
{
	Vec3 velocityCopy = this->velocity;
	const volatile float* velocityPtrX = &velocityCopy.x;
	const volatile float* velocityPtrY = &velocityCopy.y;
	const volatile float* velocityPtrZ = &velocityCopy.z;
	static const volatile int* freeMemory = new int[128];

	// Push velocity variables onto FPU stack
	ASM(push EAX)
	ASM(push EBX)
	ASM(push ECX)
	ASM(push ESI)
	ASM_MOV_REG_VAR(EAX, velocityPtrX);
	ASM_MOV_REG_VAR(EBX, velocityPtrY);
	ASM_MOV_REG_VAR(ECX, velocityPtrZ);
	ASM_MOV_REG_VAR(ESI, freeMemory);
	ASM(fld dword ptr[ECX])
	ASM(fld dword ptr[EBX])
	ASM(fld dword ptr[EAX])

from squally.

mattbucci avatar mattbucci commented on June 12, 2024

I think we can avoid at&t syntax here

Here's what stux said

here's how you get your pointer into a register:

int main(){
    int x = 42;
    int* x_ptr = &x;
    asm volatile("nop");
    asm volatile("mov rax, %0" : : "r"(x_ptr) : "rax");
    asm volatile("nop");
    x = 23;
}

generated assembly:

push   rbp
mov    rbp,rsp
sub    rsp,0x20
mov    rax,QWORD PTR fs:0x28
                
mov    QWORD PTR [rbp-0x8],rax
xor    eax,eax
mov    DWORD PTR [rbp-0x14],0x2a    ;write 42 to x
lea    rax,[rbp-0x14]               ; get the address of x
mov    QWORD PTR [rbp-0x10],rax     ; store the address of x into x_ptr
nop                                 ;sequence begin
mov    rdx,QWORD PTR [rbp-0x10]
mov    rax,rdx
nop                                 ;sequence end
mov    DWORD PTR [rbp-0x14],0x17    ;write 23 to x
mov    eax,0x0
mov    rcx,QWORD PTR [rbp-0x8]
xor    rcx,QWORD PTR fs:0x28
                
je     1188 <main+0x4f>
call   1030 <__stack_chk_fail@plt>
leave                                  
ret

from squally.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.