assembly

How to use the fixups attribute on a section?

主宰稳场 提交于 2021-02-20 01:36:28
问题 What exactly does "fixups" do when applied on a section? In a fasm sample i found the following section delcaration and i'm really not sure what the fixups attribute does, i couldn't find much information on that in the fasm documentation. section '.reloc' fixups data readable discardable if $=$$ dd 0,8 ; if there are no fixups, generate dummy entry end if 回答1: This appears to be a workaround for a bug in how FASM generates PECOFF DLLs. The .reloc section only applies to PECOFF images (EXEs

Why is this int $0x10 BIOS INT not working on Linux?

隐身守侯 提交于 2021-02-20 00:43:42
问题 I am not sure if I am doing something drastically wrong. I am learning assembly language in AT&T syntax on a linux machine with intel chip. I learned that INT 10H is used to invoke BIOS subroutines for various video purposes. I wrote this simple assembly code to clear the screen. .section .data data_items: .section .text .global _start _start: mov $6, %ah # to select the scroll function mov $0, %al # the entire page mov $7, %bh # for normal attribute mov $0, %ch # row value of the start point

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

Collatz Conjecture in Assembly shortest form

☆樱花仙子☆ 提交于 2021-02-19 07:53:05
问题 We had an assignment where we had to write the collatz conjecture in 64bit nasm assembly with only 13 commands or less (RET included). Now we are wondering how much you can actually reduce it. We are currently on 9. Heres the collatz conjecture in pseudo code for reference: Heres the code we have so far. A few notes: A tutor of us said we can remove the XOR rax, rax because of some calling convention it's already zero. It doesn't work on my computer though so I've included it here. I'm aware

GCC placing register args on the stack with a gap below local variables?

烂漫一生 提交于 2021-02-19 06:22:28
问题 I tried to look at the assembly code for a very simple program. int func(int x) { int z = 1337; return z; } With GCC -O0, every C variable has a memory address that's not optimized away, so gcc spills its register arg: (Godbolt, gcc5.5 -O0 -fverbose-asm) func: pushq %rbp # movq %rsp, %rbp #, movl %edi, -20(%rbp) # x, x movl $1337, -4(%rbp) #, z movl -4(%rbp), %eax # z, D.2332 popq %rbp # ret What is the reason that the function parameter x gets placed on the stack below the local variables?

GCC placing register args on the stack with a gap below local variables?

为君一笑 提交于 2021-02-19 06:22:26
问题 I tried to look at the assembly code for a very simple program. int func(int x) { int z = 1337; return z; } With GCC -O0, every C variable has a memory address that's not optimized away, so gcc spills its register arg: (Godbolt, gcc5.5 -O0 -fverbose-asm) func: pushq %rbp # movq %rsp, %rbp #, movl %edi, -20(%rbp) # x, x movl $1337, -4(%rbp) #, z movl -4(%rbp), %eax # z, D.2332 popq %rbp # ret What is the reason that the function parameter x gets placed on the stack below the local variables?

execve() failing to launch program in C

ぃ、小莉子 提交于 2021-02-19 06:16:08
问题 I am trying to spawn a new process using execve() from unistd.h on Linux. I have tried passing it the following parameters execve("/bin/ls", "/bin/ls", NULL); but get no result. I do not get an error either, the program just exits. Is there a reason why this is happening? I have tried launching it as root and regular user. The reason I need to use execve() is because I am trying to get it to work in an assembly call like so program: db "/bin/ls",0 mov eax, 0xb mov ebx, program mov ecx,

execve() failing to launch program in C

余生颓废 提交于 2021-02-19 06:15:40
问题 I am trying to spawn a new process using execve() from unistd.h on Linux. I have tried passing it the following parameters execve("/bin/ls", "/bin/ls", NULL); but get no result. I do not get an error either, the program just exits. Is there a reason why this is happening? I have tried launching it as root and regular user. The reason I need to use execve() is because I am trying to get it to work in an assembly call like so program: db "/bin/ls",0 mov eax, 0xb mov ebx, program mov ecx,

Why is QtSPIM telling me “Label is defined for the second time”?

泄露秘密 提交于 2021-02-19 01:06:12
问题 I am brand new to learning MIPS assembly code, and we got our first coding assignment. I am getting an error when I run my program (which is supposed to be a tester for another function we have to write) saying "spim: (parser) Label is defined for the second time on line 13 of file /home/jlr247/215_A2_work/jlr247-a2-A.s main: ^" The code I have is: .data .align 4 _arrA: .space 400 _arrB: .space 400 .text main: la $t0, _arrA #load base address of array A la $t1, _arrB #load base address of

Why is QtSPIM telling me “Label is defined for the second time”?

Deadly 提交于 2021-02-19 01:05:33
问题 I am brand new to learning MIPS assembly code, and we got our first coding assignment. I am getting an error when I run my program (which is supposed to be a tester for another function we have to write) saying "spim: (parser) Label is defined for the second time on line 13 of file /home/jlr247/215_A2_work/jlr247-a2-A.s main: ^" The code I have is: .data .align 4 _arrA: .space 400 _arrB: .space 400 .text main: la $t0, _arrA #load base address of array A la $t1, _arrB #load base address of