assembly

gcc generates unnecessary (?) instructions

陌路散爱 提交于 2020-08-15 10:38:06
问题 I decided to compile a very basic C program and take a look at the generated code with objdump -d . int main(int argc, char *argv[]) { exit(0); } After compiling it with gcc test.c -s -o test.o and then disassembling with objdump -d my text segment looked like this: Disassembly of section .text: 0000000000001050 <.text>: 1050: 31 ed xor %ebp,%ebp 1052: 49 89 d1 mov %rdx,%r9 1055: 5e pop %rsi 1056: 48 89 e2 mov %rsp,%rdx 1059: 48 83 e4 f0 and $0xfffffffffffffff0,%rsp 105d: 50 push %rax 105e:

Making a system call in GAS and using variables in .data section and accessing them for a system call inside another sub-routine

筅森魡賤 提交于 2020-08-10 20:47:27
问题 Here is the code example that I have written using GAS syntax for 64 bit intel assembly. When the code is run the expectation is to print out the string: Inside the _print subroutine. #This example is a an example to call a subroutine .global _start .section .text _start: call _print _exit: #exit call mov $60, %rax xor %rdi, %rdi syscall _print: #set up the stack frame push %rbp mov %rsp, %rbp # write syscall's parameter set up mov std_out_fd, %rdi mov $message, %rsi movq message_size, %rdx

Making a system call in GAS and using variables in .data section and accessing them for a system call inside another sub-routine

霸气de小男生 提交于 2020-08-10 20:43:26
问题 Here is the code example that I have written using GAS syntax for 64 bit intel assembly. When the code is run the expectation is to print out the string: Inside the _print subroutine. #This example is a an example to call a subroutine .global _start .section .text _start: call _print _exit: #exit call mov $60, %rax xor %rdi, %rdi syscall _print: #set up the stack frame push %rbp mov %rsp, %rbp # write syscall's parameter set up mov std_out_fd, %rdi mov $message, %rsi movq message_size, %rdx

source not found (initsect.cpp)

喜欢而已 提交于 2020-08-10 20:13:08
问题 I am trying to learn Assembly(MASM x64), and I am currently learning conditional jumps. So I wrote such a code .data .code main proc mov rax, 1 begin: cmp eax, 10 add rax, 1 jl begin main endp end Now I started a debugging process to see that it works(as there is no other way to check if something works) and at the line jl begin the debugger started to drag me the whole way through some files called exe_common.inl, file_mode.cpp, back to exe_common.inl, matherr.cpp, again back to exe_common

Golang assembly implement of _mm_add_epi32

一个人想着一个人 提交于 2020-08-10 13:10:13
问题 I'm trying to implement _mm_add_epi32 in golang assembly, optionally with help of avo. But I know little about assembly and do not even know how to start it. Can you give me some hint of code? Thank you all. Here's the equivalent slower golang version: func add(x, y []uint32) []uint32 { if len(x) != len(y) { return nil } result := make([]uint32, len(x)) for i := 0; i < len(x); i++ { result[i] = x[i] + y[i] } return result } I know that the struction paddq xmm, xmm is what we need, but do not

Fast transpose byte matrix [][]byte in Golang assembly

六眼飞鱼酱① 提交于 2020-08-10 13:08:58
问题 Matrix transpose in pure golang is slow, and using package gonum needs structure transformation which costs extra time. So a assembly version may be a better solution. Sizes of the matrix vary ( [][]byte ) or can be fixed ( [64][512]byte ), and the element type may be int32 or int64 for general scenarios. Below is a golang version: m := 64 n := 512 // orignial matrix M := make([][]byte, m) for i := 0; i < m; i++ { M[i] = make([]byte, n) } func transpose(M [][]byte) [][]byte { m := len(M) n :=

How to use character literals in GNU GAS to replace numbers?

孤者浪人 提交于 2020-08-10 05:25:35
问题 For example, I'd like to write something like 'a' instead of 0x61 like I can in C. The manual mentions them at: https://sourceware.org/binutils/docs/as/Chars.html but without an example I'm not sure I understood. 回答1: /* Immediate. Without the `$`, does a memory access, and segfaults! */ mov $'a, %al /* al == 0x61 */ /* Memory. */ mov c, %al /* al == 0x62 */ c: .byte 'b /* Space character works. */ mov $' , %al /* al == 0x20 */ /* Backslash escapes work. */ mov $'\n , %al /* al == 0x0A */

What cause segment fault after function call in assembly x64 [duplicate]

主宰稳场 提交于 2020-08-09 17:52:25
问题 This question already has answers here : Return from jump to main (1 answer) Nasm segmentation fault on RET in _start (1 answer) call subroutines conditionally in assembly (3 answers) How does $ work in NASM, exactly? (1 answer) Difference between JUMP and CALL (5 answers) Closed yesterday . My OS: Linux debian 4.19.0-9-amd64 #1 SMP Debian x86_64 GNU/Linux Compiler: NASM version 2.14 I try play with conditional jumps, function calling and comparing expressions. I wrote something simple, and

Why IDIV with -1 causes floating point exception?

折月煮酒 提交于 2020-08-09 04:42:18
问题 As far as I understood, idiv %ebx will divide edx:eax (concatenated into 64-bit value, in that order) with 32-bit ebx . However, when I try to divide 0x00000000:0xfffffffb (0 and -5) with 0xffffffff (-1), I get a floating-point exception. Can someone explain why? I'm quite puzzled why this is happening because I'm not dividing by 0 after all. Note that I know I need to sign extend edx:eax to achieve what I want, which is to calculate -5/-1 . However, even without sign extension the below

protect python code from reverse engineering

有些话、适合烂在心里 提交于 2020-08-08 07:17:32
问题 I'm creating a program in python (2.7) and I want to protect it from reverse engineering. I compiled it using cx_freeze (supplies basic security- obfuscation and anti-debugging) How can I add more protections such as obfuscation, packing, anti-debugging, encrypt the code recognize VM. I thought maybe to encrypt to payload and decrypt it on run time, but I have no clue how to do it. 回答1: Generally speaking, it's almost impossible for you to make your program unbreakable as long as there's