logo
down
shadow

Inline Assembly Procedure Crash When Accessing Arguments


Inline Assembly Procedure Crash When Accessing Arguments

Content Index :

Inline Assembly Procedure Crash When Accessing Arguments
Tag : assembly , By : mckasty
Date : November 25 2020, 07:22 PM

wish help you to fix your issue As it turns out SEGMENT was defaulting to USE16 instead of USE32/FLAT, which was causing it to be assembled in 16-bit mode, despite little explanation in the documentation.
Also as Michael said, the assembly file can be simplified to:
.model flat, C

.code

funcf   PROC
    push    EBP
    mov     EBP,    ESP
    sub     ESP,    4                   ; make space for x (4)

    mov     EAX,    DWORD PTR 8[ebp]    ; move v1 into EAX

    ...

    mov     ESP,    EBP
    pop     EBP
    ret
funcf   ENDP

END

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Accessing a register without using inline assembly with gcc


Tag : c , By : Grik
Date : March 29 2020, 07:55 AM
should help you out I want to read the stack pointer register value without writing inline assembly.The reason I want to do this is because I want to assign the stack pointer register value to an element of an array and I find it cumbersome to access an array using inline assembly. So I would want to do something like that. , There's a shortcut:
register long rsp asm ("rsp");
#include<stdio.h>

void foo(void)
{
    register long rsp asm ("rsp");
    printf("RSP: %lx\n", rsp);
}

int main()
{
    register long rsp asm ("rsp");
    printf("RSP: %lx\n", rsp);
    foo();
    return 0;
}
 $ gdb ./a.out 
GNU gdb (Gentoo 7.2 p1) 7.2
...
Reading symbols from /home/user/tmp/a.out...done.
(gdb) break foo
Breakpoint 1 at 0x400538: file t.c, line 7.
(gdb) r
Starting program: /home/user/tmp/a.out 
RSP: 7fffffffdb90

Breakpoint 1, foo () at t.c:7
7       printf("RSP: %lx\n", rsp);
(gdb) info registers
....
rsp            0x7fffffffdb80   0x7fffffffdb80
....
(gdb) n
RSP: 7fffffffdb80
8   }

passing arguments between c and inline assembly


Tag : cpp , By : Vinicios
Date : March 29 2020, 07:55 AM
To fix this issue I have a question about passing arguments between c and inline assembly , Incase anyone else comes across this I got it working.
void main()
{
    char name[] = "thisisatest";
        __asm__ ("\
        .intel_syntax noprefix     \n\
        lea, eax, %[name]          \n\
        inc BYTE PTR [eax]          \n\
       "
    :/*no output*/
    :[name]"m"(name[0])
    );
}

Accessing address of a string in inline assembly in gcc


Tag : c , By : Henry Fatino
Date : March 29 2020, 07:55 AM
this one helps. Here is my solution slightly different than above, FUZxxi for pointing it out. I should say that retrieving assembly helps in a great extent, it can be hard to understand but it gives you the actual problem. I have written enough comments if somebody wants to understand what i'm trying to achieve.
/* code to convert from lower case to upper case */
int convert(char *str)
{
   __asm__ __volatile__ ( "movl %1,%%ebx;"  // Get the address of str
                "subl $1,%%ebx;"     
        "REPEAT: addl $1,%%ebx;"    
                "movl 0(%%ebx),%%edx"  // Move the contents to edx
                "movzbl %%dl,%%ecx;"   // moving last character to ecx
                "testl %%ecx,%%ecx;"   // compare if it's null
                "je END;"              
                "cmpl $97, %%ecx;"     
                "jb END;"
                "cmpl $122,%%ecx;"
                "ja END;"
                "subb $32,(%%ebx);"  // if its lower case, subtract 32
                "jmp REPEAT;" 
          "END:;"
                :           // No output specified
                :"r"  (str) //input
                :"ecx","edx" //clobbers
             );
  printf("converted string =%s\n", str);
}

Inline assembly inefficient procedure in Delphi using SSE2


Tag : delphi , By : jonagh
Date : March 29 2020, 07:55 AM

How Get arguments value using inline assembly in C without Glibc?


Tag : c , By : Antony Briggs
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further As specified in the comment, argc and argv are provided on the stack, so you cannot use a regular C function to get them, even with inline assembly, as the compiler will touch the stack pointer to allocate the local variables, setup the stack frame & co.; hence, _start must be written in assembly, as it's done in glibc (x86; x86_64). A small stub can be written to just grab the stuff and forward it to your "real" C entrypoint according to the regular calling convention.
Here a minimal example of a program (both for x86 and x86_64) that reads argc and argv, prints all the values in argv on stdout (separated by newline) and exits using argc as status code; it can be compiled with the usual gcc -nostdlib (and -static to make sure ld.so isn't involved; not that it does any harm here).
#ifdef __x86_64__
asm(
        ".global _start\n"
        "_start:\n"
        "   xorl %ebp,%ebp\n"       // mark outermost stack frame
        "   movq 0(%rsp),%rdi\n"    // get argc
        "   lea 8(%rsp),%rsi\n"     // the arguments are pushed just below, so argv = %rbp + 8
        "   call bare_main\n"       // call our bare_main
        "   movq %rax,%rdi\n"       // take the main return code and use it as first argument for...
        "   movl $60,%eax\n"        // ... the exit syscall
        "   syscall\n"
        "   int3\n");               // just in case

asm(
        "bare_write:\n"             // write syscall wrapper; the calling convention is pretty much ok as is
        "   movq $1,%rax\n"         // 1 = write syscall on x86_64
        "   syscall\n"
        "   ret\n");
#endif
#ifdef __i386__
asm(
        ".global _start\n"
        "_start:\n"
        "   xorl %ebp,%ebp\n"       // mark outermost stack frame
        "   movl 0(%esp),%edi\n"    // argc is on the top of the stack
        "   lea 4(%esp),%esi\n"     // as above, but with 4-byte pointers
        "   sub $8,%esp\n"          // the start starts 16-byte aligned, we have to push 2*4 bytes; "waste" 8 bytes
        "   pushl %esi\n"           // to keep it aligned after pushing our arguments
        "   pushl %edi\n"
        "   call bare_main\n"       // call our bare_main
        "   add $8,%esp\n"          // fix the stack after call (actually useless here)
        "   movl %eax,%ebx\n"       // take the main return code and use it as first argument for...
        "   movl $1,%eax\n"         // ... the exit syscall
        "   int $0x80\n"
        "   int3\n");               // just in case

asm(
        "bare_write:\n"             // write syscall wrapper; convert the user-mode calling convention to the syscall convention
        "   pushl %ebx\n"           // ebx is callee-preserved
        "   movl 8(%esp),%ebx\n"    // just move stuff from the stack to the correct registers
        "   movl 12(%esp),%ecx\n"
        "   movl 16(%esp),%edx\n"
        "   mov $4,%eax\n"          // 4 = write syscall on i386
        "   int $0x80\n"
        "   popl %ebx\n"            // restore ebx
        "   ret\n");                // notice: the return value is already ok in %eax
#endif

int bare_write(int fd, const void *buf, unsigned count);

unsigned my_strlen(const char *ch) {
    const char *ptr;
    for(ptr = ch; *ptr; ++ptr);
    return ptr-ch;
}

int bare_main(int argc, char *argv[]) {
    for(int i = 0; i < argc; ++i) {
        int len = my_strlen(argv[i]);
        bare_write(1, argv[i], len);
        bare_write(1, "\n", 1);
    }
    return argc;
}
Related Posts Related QUESTIONS :
  • x86_64 Opcode encoding formats in the intel manual
  • Should using MOV instruction to set SS to 0x0000 cause fault #GP(0) in 64-bit mode?
  • How to change the foreground color of a string (32 Bit Assembly kernel)?
  • Is this AND+CMP between the same two operands just checking for one of them being zero?
  • segmentation fault while calling functions in nasm assembly
  • String reverse with x64 SSE / AVX registers
  • How Can Assembly Program Multitask Two Or More Tasks In The Same Time?
  • Cortex M7 floating arithmetic instruction duration with zero operand
  • How does mulw, prodl and prodh work together in assembler programming?
  • Questions about APIC interrupt
  • assembly: position of static/ global variables
  • When is the zero flag set?
  • how TEST instruction check if number is EVEN or ODD in assembly language
  • What does "Undefined" mean in Intel's asm documentation? FST effect on C0, C2, C3
  • How to decompile 64-bit binary to retrieve content?
  • BIOS Always Fails to Perform Disk Operations
  • My TSR program freezes when executed a second time
  • ARM assembly syntax in VST/VLD commands
  • Do assembly instructions map 1-1 to machine language?
  • What are the technical mechanics and operation of declaring variables in 32-bit MASM?
  • How are the SCAS and MOVS instructions affected by the value of the direction EFLAG?
  • Pointer to string in stand-alone binary code without .data section
  • How to enable MMU in QEMU (virt machine a57 cpu)
  • How to count character of a string in assembly not use 0Ah/int21h
  • mips nested procedure with jr $ra
  • NASM-64bits-segmentation fault calling procedure
  • Is it possible to map a process into memory without mapping the kernel?
  • Index an array with constants with Turbo C++ inline asm
  • SIMD vectorize atan2 using ARM NEON assembly
  • Assembly TASM: Multiply 4 digit numbers by 4 digit numbers
  • How do assembly instruction differentiate between register, memory address, immediate value or offset parameter?
  • How can segmentation be used to expand memory?
  • Print spaces between every numbers that's printed in 8086 Assembly
  • the why of MOV command restrictions
  • Why a Word is 2 bytes and not 4 bytes in x86 Assembly?
  • Assembly memory operands clarification
  • Syntax error in assembly when using letter "C"
  • 6502 XASM defini data
  • How do I identify the instruction stored LC-3
  • Int 21h/ah=39h returns with AX=3 upon directory creation
  • Filling up Delayed Branch slots
  • Syntax to read IA32 register with offset in GDB?
  • What is the purpose of positive EBP referencing?
  • What does the following byte specifier for adding to a memory reference does in NASM assembler?
  • Can I read label value in assembly?
  • How to create a void function in Assembly?
  • FAT32 Finding Stage 2 Bootloader
  • Passing a 1 byte argument to a function?
  • fail to read sectors on boot code
  • Bootloader - Loading assembly kernel, problems with memory addresses and copying data
  • Moving AX into CL - Invalid combination of opcode and operands
  • Number representation in Assembler
  • lwzx PowerPC Assembly on Dolphin Wii Emulator
  • nasm assembly for loop
  • Division produces wrong result
  • Illegal Number Error - lowercase to uppercase conversion (0xdf)
  • Counting occurances of a negative number from a list
  • The difference between signed and unsigned, what means a negative byte?
  • Beeping Bootloader (Intel x86)
  • using atof function in x86 NASM
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com