assembly

What do the gcc assembly output labels signify?

情到浓时终转凉″ 提交于 2020-07-06 12:22:34
问题 I've written a simple C program test.c : #include <stdio.h> #include <stdlib.h> int add(int a, int b); int main() { int i=5,j=10; int result; result = add(i, j); printf("result is %d\n", result); } int add(int a, int b) { return (a + b); } and I compiled it: gcc -S -Os -o test.s test.c and I get the assembly file test.s : .file "test3.c" .section .rodata .LC0: .string "result is %d\n" .text .globl main .type main, @function main: .LFB5: pushq %rbp .LCFI0: movq %rsp, %rbp .LCFI1: subq $16,

Why does .NET Native compile loop in reverse order?

廉价感情. 提交于 2020-07-06 11:15:27
问题 I'm working on optimization techniques performed by the .NET Native compiler. I've created a sample loop: for (int i = 0; i < 100; i++) { Function(); } And I've compiled it with Native. Then I disassembled the result .dll file with machine code inside in IDA. As the result, I have: (I've removed a few unnecessary lines, so don't worry that address lines are inconsistent) I understand that add esi, 0FFFFFFFFh means really subtract one from esi and alter Zero Flag if needed , so we can jump to

Why does .NET Native compile loop in reverse order?

北城以北 提交于 2020-07-06 11:15:26
问题 I'm working on optimization techniques performed by the .NET Native compiler. I've created a sample loop: for (int i = 0; i < 100; i++) { Function(); } And I've compiled it with Native. Then I disassembled the result .dll file with machine code inside in IDA. As the result, I have: (I've removed a few unnecessary lines, so don't worry that address lines are inconsistent) I understand that add esi, 0FFFFFFFFh means really subtract one from esi and alter Zero Flag if needed , so we can jump to

Get size of x86-64 instruction

∥☆過路亽.° 提交于 2020-07-05 07:51:12
问题 I need a function which can calculate the length of an x86-64 instruction. For example, it would be usable like so: char ret[] = { 0xc3 }; size_t length = instructionLength(ret); length would be set to 1 in this example. I do not want to include an entire disassembly library, since the only information I require is the length of the instruction. I am looking for a minimalist approach, written in C, and ideally as small as possible. 100% complete x86-64 instruction set is not strictly

Understanding intel SUB instruction

心已入冬 提交于 2020-06-29 03:48:16
问题 I am currently trying to deepen my understanding of assembly code and I am stuck since weeks with a seemingly simple instruction : sub al, BYTE PTR [ebp+4] Assuming eax = 0x11223300 and BYTE PTR [ebp+4] = 0xaa what is the value of eax after the above instruction ? From what I understand, al can only affect the last byte in eax ( 0x00 in this case) so the program tries to compute 0x00 - 0xaa . But the result being negative, I don't get if the result would simply be 0x00 or if numbers are

error: unsupported size for integer register

谁都会走 提交于 2020-06-29 03:39:16
问题 I'm using i686 gcc on windows. When I built the code with separate asm statements, it worked. However, when I try to combine it into one statement, it doesn't build and gives me a error: unsupported size for integer register . Here's my code u8 lstatus; u8 lsectors_read; u8 data_buffer; void operate(u8 opcode, u8 sector_size, u8 track, u8 sector, u8 head, u8 drive, u8* buffer, u8* status, u8* sectors_read) { asm volatile("mov %3, %%ah;\n" "mov %4, %%al;\n" "mov %5, %%ch;\n" "mov %6, %%cl;\n"

Absolute values (assembly)

荒凉一梦 提交于 2020-06-28 06:44:11
问题 I want to obtain the absolute values of all the elements that are stored in a specific array (i'm using MC 68HC11) ABSOLUTE will contain the absolute values of the elements stored in ARRAY (the size of ABSOLUTE must be related to the amount of elements inside ARRAY) In C it looks like this: #include <stdio.h> #define SIZE 16 int absolute(int array[], int ray[], int N) { for (int i=0; i<N; i++) ray[i] = array[i] * (array[i]<0?-1:1); } int main() { int array[SIZE] = {0,1,2,3,-4,5,6,7,-8,9,-10

Absolute values (assembly)

回眸只為那壹抹淺笑 提交于 2020-06-28 06:44:09
问题 I want to obtain the absolute values of all the elements that are stored in a specific array (i'm using MC 68HC11) ABSOLUTE will contain the absolute values of the elements stored in ARRAY (the size of ABSOLUTE must be related to the amount of elements inside ARRAY) In C it looks like this: #include <stdio.h> #define SIZE 16 int absolute(int array[], int ray[], int N) { for (int i=0; i<N; i++) ray[i] = array[i] * (array[i]<0?-1:1); } int main() { int array[SIZE] = {0,1,2,3,-4,5,6,7,-8,9,-10

Positive, negative and zero (assembly)

混江龙づ霸主 提交于 2020-06-28 06:43:07
问题 I'm programming an old MCU (68hc11), I'm trying to migrate from C language to assembly code using the 68hc11 instructions. I want to write a program in assembly that counts the number of POSITIVE, NEGATIVE, and ZERO values that exist inside a given array. DO NOTE that all values inside ARRAY could be all positive or all negative or all zeros,do you get me? So I should define the size of the variables that will store the quantity properly. NOTE: The end of the array is: ARRAY+QUANTITY-1 Array:

Segfault when loading function parameter into a register

拜拜、爱过 提交于 2020-06-28 05:04:21
问题 I'm quite new to x86 assembly, and I'm trying to build off a hello world program. I'm trying to make a subroutine, that writes a single byte to stdout, but i've hit a problem. The line mov ebx, [esp+1] (to load the byte passed, when I call the subroutine) causes a segfault. I've tried xoring the ebx register with itself, to make sure that it is empty, to make sure, that it doesn't mess with the syscall _start: push 32h call _writeByte ; This just jumps to an exit routine jmp _exit _writeByte: