Questions tagged [x86-64]

0

votes
0

answer
3

Views

How to use the umonitor / umwait instructions in x86-64 assembly on Mac

I just learned of umonitor/umwait which are any-privilege-level monitor/mwait instructions. Of the umwait, it says: A hint that allows the processor to stop instruction execution and enter an implementation-dependent optimized state until occurrence of a class of events.... instructs the processor t...
Lance Pollard
1

votes
1

answer
58

Views

64 bits kernel weird behaviour

Im having trouble to understand this problem: I have this code that gets called by a bootloader but when i compile and run a test that should print HELLO, one of this three things may happen: If i declare another variable of type unsigned the code will print only half of the string (HE). If i declar...
Tretorn
1

votes
1

answer
56

Views

recursively deleting files in x64 assembly

So i need to recursievly delete files in a directory using x86_64 assembly. here is my code and i know it is bad. My problem is that every syscall works individualy(i can individualy delete directories or documents) , But as soon as i merge them together like this, it doesn't work . #edit: as pointe...
starboy
1

votes
1

answer
44

Views

Why doesn't this assembly code print the top of the stack?

After successfully making a 'Hello, World!' program in x86-64, I wanted to make a program that can peek at the top of the stack (without popping it, and using the esp register so I can learn how it works). This is the program in NASM: extern GetStdHandle, WriteConsoleA, ExitProcess section .bss dumm...
FireCubez
0

votes
0

answer
19

Views

Why and how exactly does casting to and from void * lead to violation of alignment restrictions? [on hold]

Why and how exactly does casting to and from void * lead to violation of alignment restrictions? Considering that the size of the pointer will be something like 4 bytes, whatever the type involved.
Josiah
3

votes
0

answer
16

Views

what would be the benefit of moving a register to itself in x86-64

I'm doing a project in x86-64 NASM and came across the instruction: mov rdi, rdi I have searched all over but can't find mention of why this would be needed. Does it affect the flags or is it something clever that I don't understand? To give some context its present in a loop right before the same...
nrmad
1

votes
1

answer
569

Views

Unable to do overlap block transfer in Assembly

I have made a program in Assembly language(nasm) to do overlap block transfer i.e., if one of my array contains '10, 20, 30, 40, 50'(without quotes) then after overlapping of for example 2 elements my resulting array should contain '10, 20, 10, 20, 30, 40, 50'(without quotes). But my problem is when...
Paras
1

votes
2

answer
906

Views

How to take a string as a input in Assembly x64

I am writing a program to check if a string is Palindrome or not. I want to take a string as input from user. The string can contain any character ranging from digits to special characters. How can I take input from user. I have tried the following code. global _start section .bss string resb 9 sect...
Paras
1

votes
1

answer
1.4k

Views

dma_alloc_coherent failed on x86_64 but works on i686

I have a driver for pci device which uses CMA allocation mechanism for DMA allocations. It works fine on kernel 3.18 in 32bit mode but when I try to use it in 64 kernel(same config as in 32bit, but switched on 64bit mode) dma allocation failed. Only thing I see in dmesg is: fallback device: swiotlb...
dtoch
1

votes
2

answer
174

Views

(Assembly) Is it possible to shr in the %eax register (x64) and still end up with a signed number?

shr sets the highest order bit to zero. is it still possible to nevertheless end with a signed number? I have to cmpl with null and trigger a signed flag. e.g. shr %eax // I have %rax available if necessary mov %eax -0x4(%rbp) cmpl 0x0 -0x4(%rbp) (then something that checks the signed flag) Edit: So...
freenet16
1

votes
2

answer
61

Views

Assuming AMD64 calling convention would be standard could Windows and Linux have shared code?

AMD64 has different calling conventions on Linux and Windows but imagine if they were the same would it be possible to have code share amongst them? I know there is difference between COFF and ELF, and things like shared libraries are different (GOT vs whatever Windows does) and function names are o...
halivingston
1

votes
1

answer
143

Views

How to set color when call printf in assembly

I want to set the color when I call printf from assembly. This is my code: Out: mov rdi, answer mov rsi, r10 mov rax,0 call printf section .data answer: db '\033[0;31m%d\033[0m',10,0 I use NASM to compile and gcc to link nasm -f elf64 '%f' gcc -o %e %e.o However, the out...
CXWorks
1

votes
1

answer
328

Views

Use of shl and rol in assembly input and output

I am writing assembly code to accept n numbers from users to perform addition. Why shl and rol instructions are used while taking input and displaying output? Code: takeno: print msg2,len2 ;calls a macro to display 'Enter number' accept var2,17 ;accepts number in var2 xor rbx,rbx mov rsi,var2...
daemontosh
1

votes
1

answer
550

Views

Assembly - Unable to set breakpoints lldb

I assembled with these options nasm -O0 -g -f macho64 but lldb complains of 'Unable to resolve breakpoint to any actual locations.' when i try to set any breakpoints at line numbers in the file. I've started trying to learn 64 bit assembly for OS X but it's proving a real challenge so far, there see...
zMesh
1

votes
2

answer
61

Views

Why is “amd” written in many installers?

I have seen many installers like that of Python and Ubuntu which has 'amd' on them. Why is that so? Can I run those programs on my laptop having intel cpu? Please explain to me in detail. Thanks :)
Tanay
1

votes
1

answer
281

Views

How to disable bmi instructions with GCC 4.4.7-17

I have a problem with gcc 4.4.7-17. I compiled a program in a server and ran this program in another server, but it crashed because of illegal instruction. I doubt that the difference between the two servers may cause this exception.Yes, I find that the server compiling program has CPU flag bmi1 an...
Eric Lee
1

votes
1

answer
27

Views

comprehending how “volatile” keyword and comparison work

If a variable is not specified with the keyword volatile, the compiler likely does caching. The variable must be accessed from memory always otherwise until its transaction unit ends. The point I wonder lies in assembly part. int main() { /* volatile */ int lock = 999; while (lock); } On x86-64-cla...
snr
1

votes
1

answer
105

Views

Loop Segmentation Fault

This is my code so far. .data S: .string '-149' Length: .byte -1 Result: .quad .text .globl main main: mov S,%rdx #Storage of string, counter, position and result in memory mov Length, %rcx mov Result, %rax mov $10, %r10 mov $30, %r13 mov $-1...
Egyptian_Coder
1

votes
1

answer
55

Views

Why isn't gdb showing me the change in a BSS array when I calculate the address with the same expression as the addressing mode?

Wrote simple program with large buffer in .bss segment h_vals: resq 99999 then tried to increment value of some array cell. mov rcx, [h_vals+8*rax] inc rcx mov [h_vals+8*rax], rcx Still in gdb see the same value(0) both before and after third instruction execution. x/dg &h_vals &h_vals + 8 * $rax 0x...
Bulat M.
1

votes
1

answer
75

Views

Is there a way to have a.out loaded in linux x86_64 “high memory”?

If I look at the memory mapping for a 64-bit process on Linux (x86_64) I see that the a.out is mapped in fairly low memory: $ cat /proc/1160/maps 00400000-004dd000 r-xp 00000000 103:03 536876177 /usr/bin/bash 006dc000-006dd000 r--p 000dc000 103:03 536876177...
Peeter Joot
1

votes
1

answer
1k

Views

x86-64 Assembly “cmovge” to C code

While I shouldn't list out the entire 4 line sample I'm given, (since this is a homework question) I'm confused how this should be read and translated into C. cmovge %edi, %eax What I understand so far is that the instruction is a conditional move for when the result is >=. It's comparing the first...
1

votes
1

answer
55

Views

How to determine where this address comes from on 64-bit macOS application

So I'm currently debugging an issue, and trying to figure out how this could happen. Here is the assembly for a method in the obj-c runtime, called objc_msgsend() libobjc.A.dylib`objc_msgSend: 0x7fff9084a0c0 : testq %rdi, %rdi 0x7fff9084a0c3 : je 0x7fff9084a140 ; 0x7fff9084a0c6...
A O
2

votes
0

answer
13

Views

Newline byte 0Ah being ignored by x86_64 system call print program

I followed a simple tutorial in the creation of a NASM x86_64 program which uses the defined functions to print variables with a new line added to the end. sprintLF calls sprint which in turn prints whatever is in rax having set up the appropriate system call. On return sprintLF updates rax with 0Ah...
nrmad
1

votes
1

answer
189

Views

Buffer overflow needs 16 bytes on x86 but 29 bytes on x64

#include #include int main(int argc, char **argv) { char buff[15]; int auth = 0; printf('\nEnter password: '); gets(buff); if (strcmp(buff, 'password') != 0) { printf('\nAccess denied\n'); } else { auth = 1; } if (auth) { printf('\nAccess granted\n'); } return 0; } This piece of code needs 16 byte...
Aaron
1

votes
1

answer
77

Views

How can I save parameter (passed by C function call) to global variable in assembler x86-64?

in my test.c file: size_t var = 1000; foo(var); in test.h: int *foo(size_t var); in test.asm: global foo section .bss N: resd 0 ; ... foo: ; how can I get to 'var' here and how can I write it to 'N'? I tried writing something like: push rbp mov rbp, rsp mov rax, [rbp+8] mov [N], rax p...
Jecke
1

votes
1

answer
693

Views

GDB - Assembly program returns /bin/sh: 0: Can't open �

I am presently learning 64-bit assembly language from the related Pentester Academy course. The code I'm working on creates the following error when ran in GDB: /bin/sh: 0: Can't open � [Inferior 1 (process 4049) exited with code 0177] I have googled the error and exit code and haven't found anyt...
adam
1

votes
1

answer
71

Views

Assembly number change error

I tried to make a assembly program that took one number, and then printed it. But when I wrote 1, it wrote 4171. Why, and how can I fix it? I am using 64 bit assembly, I assembled it with nasm -f macho64 scanf.asm, and I linked it with gcc -o scanf scanf.o -Wl,-no-pie. And I've tried to use square b...
SpilledMango
1

votes
2

answer
1.4k

Views

GDB Debugger: An internal issue to GDB has been detected

I'm new to GNU Debugger. I've been playing around with it, debugging Assembly Files (x86_64 Linux) for a day or so and just a few hours ago I ''discovered'' the TUI interface. My first attempt using the TUI interface was to see the register changes as I execute each line at a time of a simple Hello...
Jazz
1

votes
1

answer
90

Views

Why does Apple use R8l for the byte registers instead of R8b?

I saw this in Making Code 64-Bit Clean topic ╔═════════════════════╤══════════════════════════════════════════════════════╗ ║ Register name...
phuclv
1

votes
1

answer
752

Views

Logarithm in C++ and assembly

Apparently MSVC++2017 toolset v141 (x64 Release configuration) doesn't use FYL2X x86_64 assembly instruction via a C/C++ intrinsic, but rather C++ log() or log2() usages result in a real call to a long function which seems to implement an approximation of logarithm (without using FYL2X). The perform...
Serge Rogatch
1

votes
1

answer
58

Views

Can I use 1G superpages to back shared mmaps?

So far when I've tried using a file in /mnt/hugepages1G/ as the backing I get segfaults. It works fine if I use 2M superpages in /mnt/hugepages/ I think I read somewhere that I now can't find that Linux only supports 2M pages for Shared memory? But I can't swear to it. Can't find it in documentation...
Hal
1

votes
1

answer
82

Views

Zero extending a part of register [duplicate]

This question already has an answer here: Why do x86-64 instructions on 32-bit registers zero the upper part of the full 64-bit register? 2 answers I'm debugging the following function: _print_func: mov rdx, 0xFFFFFFFFFFFFFFFF mov rax, 0x01 mov rdi, 0x01 mov rsi, str movzx dx, byte [str_len] ;
St.Antario
1

votes
1

answer
392

Views

GCC store all strings in .rodata

In my x86-64 kernel, I am trying to map the .rodata ELF section as readonly. But all the string literals, are stored in a file-specific section, e.g. .rodata.str1.8. Are there any option for GCC to store all strings in .rodata instead, or can I concatenate the .rodata.str.x into .rodata using ld, ob...
SpilledMango
1

votes
1

answer
107

Views

Write function 'print_string' which accepts a pointer to a null-terminated string and prints it to stdout

I am currently going through Zhirkov's book, 'Low Level Programming' for the purpose of self-learning. I am stuck on the end of chapter two, the assignment. I have written the first function, string_length, which accepts a pointer to a string and returns its length. I have also created a test print_...
Jonathan Dewein
1

votes
1

answer
227

Views

Tell 'ld' dyld_stub_binder is no longer in libSystem.dyld but in libSystem.B.dyld

I am trying to re-create the Launchpad executable and so far everything seems right except I get this warning when I run ld: Assembling/Linking with: as myprogram.s -o myprogram.o ld myprogram.o -arch x86_64 -macosx_version_min 10.12 -e _start -framework Foundation -framework ApplicationServices -o...
JLegendre
1

votes
2

answer
104

Views

What software-visible processor state needs to go in a jmp_buf on an x86-64 processor?

As stated, what software-visible processor state needs to go in a jmp_buf on an x86-64 processor when setjmp(jmp_buf env) is called? What processor state does not? I have been reading a lot about setjmp and longjmp but couldn't find a clear answer to my question. I know it is implementation dependen...
gammaALpha
1

votes
1

answer
97

Views

Segfault calling c function from assembly

I am attempting to set up some pointers in an assembly program(AT&T syntax running on x86_64 linux), then pass them to a C program to essentially add their values. Of course, this isn't the most effective way of accomplishing the end result, but I'm trying to understand how to make something like th...
user2649681
1

votes
1

answer
174

Views

Linux 64-abi, calling convention

I'm reading intel manual about calling convention and which register has which purpose. Here is what was specified in the Figure 3.4: Register Usage: %rax temporary register; with variable arguments passes information about the number of vector registers used; 1st return register But in linux...
St.Antario
1

votes
1

answer
248

Views

Understanding x86-64 assembly code in Xcode

I don't have a lot of experience working with assembly or x86-64, and I'm having trouble understanding this assembly code provided by Xcode while debugging an iOS version-specific bug: 0x108f5607a : movq 0x3fe98f(%rip), %rsi ; 'intrinsicContentSize' 0x108f56081 : movq 0x47c158(%rip), %r12...
peco
1

votes
2

answer
286

Views

Why are segfaults called faults (and not aborts) if they are not recoverable?

My following understanding of the terminology is this 1) An interrupt is 'a notification' that is initiated by the hardware to call the OS to run its handlers 2) A trap is 'a notification' that is initiated by the softare to call the OS to run its handlers 3) A fault is an exception that is raised b...
AlanSTACK

View additional questions