assembly

Android Studio 64 bit inline ARM assembly

自作多情 提交于 2021-01-29 20:00:54
问题 I am trying to run some inline assembly code for aarch64 from Android Studio 3.4.2 and I got a compilation error error: Don't know how to handle indirect register inputs yet for constraint 'r' . My code snippet as follows std::string system_file = "/system/bin/sh"; std::int64_t file_descriptor = -1; #ifdef __aarch64__ __asm__ volatile("mov x8, #180\n\t" "mov x0, %1\n\t" "mov x1, #0\n\t" "svc #1\n\t" "mov %0, x0\n\t" :"=r"(file_descriptor) :"r"(system_file) :"x0","x1","x8" ); #endif ARM64

Calling sprintf in x64 assembly

老子叫甜甜 提交于 2021-01-29 19:18:22
问题 It seems that I can't call sprintf() correctly in assembly. When I try to dprintf() my buffer that should now be formatted, all I get is: (null) and a segmentation fault. When running lldb with my program, strlen() is the reason of the fail as it can't find a \0 in my buffer. Here's my code: mov rdi, buff mov rsi, 0 mov rdx, 17 call memset lea rsi, [rel n_head] mov rdx, rax call sprintf mov rdx, rdi lea rsi, [rel fmt] mov rdi, 1 call dprintf ... section .data n_head: db "Low battery: %d%%", 0

Import constants in x86 with gas

≯℡__Kan透↙ 提交于 2021-01-29 18:25:48
问题 I have the following two files in assembly: # file.s .globl _start _start: mov $10, %edi mov $SYS_EXIT, %eax syscall # utils.s SYS_EXIT = 60 SYS_WRITE = 1 SYS_STDOUT = 1 What is required to be able to link these two files into an executable. To assemble and link I've tried doing: $ as file.s -o file.o $ as utils.s -o utils.o $ ld utils.o file.o -o file # file.o: In function `_start': # (.text+0x8): undefined reference to `SYS_EXIT' Which seems to just mean I'm not properly importing the file

Are these the smallest possible x86 macros for these stack operations?

廉价感情. 提交于 2021-01-29 17:03:41
问题 I'm making a stack based language as a fun personal project. So, I have some signed/unsigned 32-bit values on the stack and my goal is to write some assembly macros that operate on this stack. Ideally these will be small since they'll be used a lot. Since I'm new to x86 assembly I was wondering if you guys had any tips or improvements you could think of. I'd greatly appreciate your time, thanks! Note: An optimizer is used after the macros are expanded to avoid cases like pop eax; push eax so

Coverting String Decimal to Binary and Hexa in Assembly 8086

陌路散爱 提交于 2021-01-29 16:14:29
问题 I'm trying to convert a string I read with this code to binary and hexa. READ_STRING: MOV DX, offset buffer MOV AH, 0Ah INT 21h MOV SI, 1d MOV AX, 0 XOR CX, CX MOV CL, buffer[SI] INC SI LOOP_1: MOV DX, 10 MUL DX MOV DL, buffer[SI] SUB DL, 30h MOV DH, 0 ADD AX, DX INC SI LOOP LOOP_1 RET So far I have this code for binary output but it always prints "1001" (9 in decimal): NEXT: XOR AX, AX XOR BX, BX XOR CX, CX MOV CL, 2 MOV AL, byte ptr[nombre] MOV DI, offset binaire ; DIV : divide AX by CL.

Can't output coprocessor float from variable two times in a row

谁说胖子不能爱 提交于 2021-01-29 14:35:55
问题 Good afternoon! In this example, I simply add two numbers with a comma, save the variable in tbyte and display the same variable two times in a row on the screen, but the first time I get 11.1 , as it should be, and the second time 4.667261E-062 . Why is this happening? And one more question, is it possible in tbyte to somehow save and access numbers by array type? for example, storing numbers in dd , I just could save and read them in increments of 4, for example, result [0] , result [4] ,

push same value onto stack and ret behaves differently

感情迁移 提交于 2021-01-29 14:31:24
问题 In x-86, if you push a value from a register (for example, %eax), and then return, the program transfers control to the address corresponding to the value at %eax, to my understanding. In another run of the program, if you edited the code so that you pushed onto the stack through a different way (for example, such as dereferencing a register, moving that value to another register, and then pushing this register), and then return, the program should also transfer control to the address

Remove needless assembler statements from g++ output

橙三吉。 提交于 2021-01-29 14:31:16
问题 I am investigating some problem with a local binary. I've noticed that g++ creates a lot of ASM output that seems unnecessary to me. Example with -O0 : Derived::Derived(): pushq %rbp movq %rsp, %rbp subq $16, %rsp <--- just need 8 bytes for the movq to -8(%rbp), why -16? movq %rdi, -8(%rbp) movq -8(%rbp), %rax movq %rax, %rdi <--- now we have moved rdi onto itself. call Base::Base() leaq 16+vtable for Derived(%rip), %rdx movq -8(%rbp), %rax <--- effectively %edi, does not point into this area

How to convert an 8086 emu assembly program to linux assembly comaptible

点点圈 提交于 2021-01-29 14:17:12
问题 I am writing a code to convert hex (A-F) to decimal in assembly. I managed to write it on 8086 emu but I need it for linux. I need help. The code works absolutely fine on 8086 emulator n windows. But I am unable to convert it into Linux syntax. I am not familiar with the Linux Syntax for assembly. This is my 8686 code. org 100h .model small .stack 100h .data msg1 db 'Enter a hex digit:$' msg2 db 'In decimal it is:$' .code main proc mov ax,@data mov ds,ax lea dx,msg1 mov ah,9 int 21h mov ah,1

Whay rip is used here in a Hello world assembly? [duplicate]

孤街醉人 提交于 2021-01-29 14:11:34
问题 This question already has answers here : Why is the address of static variables relative to the Instruction Pointer? (1 answer) Why are global variables in x86-64 accessed relative to the instruction pointer? (2 answers) Closed 12 months ago . I found some assembly code about "hello world", but I don't understand leaq L1(%rip), %rdi, why rip is used here? .text .globl _main _main: pushq %rbp movq %rsp, %rbp leaq L1(%rip), %rdi <--it's the first time that I found IP is directly used in code.