x86-64

Why does not XORing %eax causes segfault? [duplicate]

别等时光非礼了梦想. 提交于 2020-06-17 13:21:25
问题 This question already has answers here : Segmentation fault on printf - NASM 64bit Linux (1 answer) Calling printf in x86_64 using GNU assembler (2 answers) main and stack alignment (1 answer) Why does System V / AMD64 ABI mandate a 16 byte stack alignment? (1 answer) Closed 12 days ago . .text having this: str: .string "string" .globl main main: xor %eax, %eax #is commented causes segfault leaq str(%rip), %rdi call printf xorq %rdi, %rdi call exit Does printf uses %rax ? or is the segfault

ctime returning null

早过忘川 提交于 2020-06-17 03:47:28
问题 If the user type time_t is defined as __darwin_time_t , which itself is defined as long in MacOS X, why does the following code outputs 8 Time is (null) ? Maybe it's something silly, but I can't really understand it. #include <stdio.h> #include <time.h> int main(void) { time_t time = 0x7FFFFFFFFFFFFFFF; printf("%lu\n" "Time is %s\n", sizeof(time_t), ctime(&time)); return 0; } 回答1: Time 0x7FFFFFFFFFFFFFFF appears to be around the year 292,471,210,647 AD, which undoubtedly causes ctime to

Copying to arrays in NASM

╄→尐↘猪︶ㄣ 提交于 2020-06-16 08:41:53
问题 I have to write in assembly code which copy 100 bytes in memory in loop. I wrote it like this: section .data a times 100 db 1 ;reserve 100 bytes and fill with 1 b times 100 db 0 ;reserve 100 bytes and fill with 0 section _start global _start _start: mov rsi, a ;get array a address mov rdi, b ;get arrat b address _for: ;początek pętli cmp cx, 100 ;loop jae _end_for ;loop push cx ;loop mov byte al, [rsi] ;get one byte from array a from al mov byte [rdi], al ;put one byte from al to array b inc

What is the “C++ ABI Specification” referred to in GCC's manual?

怎甘沉沦 提交于 2020-06-14 07:45:07
问题 I was looking at the GCC manual for C++, and I came across the following quote: Version 0 refers to the version conforming most closely to the C++ ABI specification. Therefore, the ABI obtained using version 0 will change in different versions of G++ as ABI bugs are fixed. (source) As can be seen, the above passage references some sort of seemingly standard C++ ABI. As I understand it, however, no such ABI exists. What is this passage talking about? A good answer will give as thorough an

Assemble far calls or far jumps (j* instructions)

我怕爱的太早我们不能终老 提交于 2020-06-12 09:11:27
问题 I'm trying to create a dispatch table which changes the location of some instruction in another address which is allocated by AllocateMemoryOnRemoteProcess . One of the problems that I encountered was almost all of Calls and all kind of Jumps are near and relative and as long as I load the assemblies in new location, then these instructions won't work. As I know I should convert these instructions to far jump or far call one of the solutions that I saw during my googling was using push and

Assemble far calls or far jumps (j* instructions)

断了今生、忘了曾经 提交于 2020-06-12 09:10:49
问题 I'm trying to create a dispatch table which changes the location of some instruction in another address which is allocated by AllocateMemoryOnRemoteProcess . One of the problems that I encountered was almost all of Calls and all kind of Jumps are near and relative and as long as I load the assemblies in new location, then these instructions won't work. As I know I should convert these instructions to far jump or far call one of the solutions that I saw during my googling was using push and

How syscall knows where to jump? [closed]

三世轮回 提交于 2020-06-12 04:42:48
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 11 months ago . How does Linux determine the address of another process to execute with a syscall? Like in this example? mov rax, 59 mov rdi, progName syscall It seems there is a bit of confusion with my question, to clarify, what I was asking is how does syscall works, independently of the

Linker error when calling printf from _start [duplicate]

為{幸葍}努か 提交于 2020-06-09 04:17:28
问题 This question already has answers here : Assembling 32-bit binaries on a 64-bit system (GNU toolchain) (2 answers) Closed 3 years ago . I tried to write simple program without main segment .data fmt db "test", 0xa, 0 segment .text global _start extern printf _start: lea rdi, [fmt] ; print simple string xor eax, eax call printf mov eax, 60 ; exit successfully xor edi, edi syscall Compile: yasm -f elf64 main.s; ld -o main main.o Got main.o: In function `_start': main.s:(.text+0xb): undefined

Linker error when calling printf from _start [duplicate]

浪尽此生 提交于 2020-06-09 04:17:06
问题 This question already has answers here : Assembling 32-bit binaries on a 64-bit system (GNU toolchain) (2 answers) Closed 3 years ago . I tried to write simple program without main segment .data fmt db "test", 0xa, 0 segment .text global _start extern printf _start: lea rdi, [fmt] ; print simple string xor eax, eax call printf mov eax, 60 ; exit successfully xor edi, edi syscall Compile: yasm -f elf64 main.s; ld -o main main.o Got main.o: In function `_start': main.s:(.text+0xb): undefined

Why does C not push a pointer on the stack when calling a assembly function?

落爺英雄遲暮 提交于 2020-06-09 02:47:11
问题 I am currently trying to get some experience with calling assembly functions from C. Therefore, I created a little program which calculates the sum of all array elements. The C Code looks like this: #include <stdio.h> #include <stdint.h> extern int32_t arrsum(int32_t* arr,int32_t length); int main() { int32_t test[] = {1,2,3}; int32_t length = 3; int32_t sum = arrsum(test,length); printf("Sum of arr: %d\n",sum); return 0; } And the assembly function looks like this: .text .global arrsum