FAQ Database Discussion Community


How to do a jump based on cmpss output (floating-point compare)?

assembly,x86
According to this reference, I can compare if xmm1 and xmm2 are equal by doing the following: cmpss xmm2, xmm1, 0 However, it seems that the zero flag is not set. Instead, the result is stored in xmm2. How do I do a jump based on whether or not they're...

ASM : Trouble using int21h on real machine

assembly,x86,bootloader
I want to input a char in ASM compare it to a defined char and print a message if they are the same or retry if they aren't Problem is that my code works on emu8086 but not on a VM: mdp DB 'c$' equal : mov ah, 1h int...

Does RIP-relative addressing require 16-byte aligned?

assembly,x86,x86-64
The test is on 64-bit/x86 Ubuntu 12.04. With GCC 4.6.3. So basically I am manipulating some x64 assembly code. And I observed that RIP-relative addressing require the absolute address to be 16-byte aligned. Here is an example when debugging using gdb: 0x40f38d <S_0x40F614+61> xorpd 0x84d3(%rip),%xmm0 # 0x417868 <S_0x417DE0> This memory...

Assembly (x86):

assembly,x86,bootloader,16-bit
I've been banging my head against the wall in an attempt to understand why the following assembly is not correctly dumping the contents of 'HELLO_WORLD'. ; Explicitly set 16-bit [ BITS 16 ] [ ORG 0x7C00 ] ; Create label for hello world string terminated by null. HELLO_WORLD db 'hello...

Equivalent to asm volatile in Gfortran?

assembly,gfortran
Is there an equivalent to Gcc's inline assembly in Gfortran? __asm__ __volatile__ (...) I cannot find anything in the gfortran man page, or the manual....

LC3 assembly-unable to print the right character

assembly,encryption,lc3
I have been trying to make a program that decrypts a text that is being read from a file under the following condiditons: The adress of the first element of the file is 5001.Each letter is encrypted twice:The first time with Ceasar encryption and the second time with XOR encryption.The...

MASM SEG operator

assembly,masm
Let's assume we are writing assembly code using MASM 6.1 / 16 bit / huge data model, and we have a variable (label) named MY_VAR, a segment named MY_SEG and a segment group named MY_GROUP. Let's assume MY_VAR is placed in MY_SEG, and MY_SEG belongs to MY_GROUP. Then, what is...

Macro to push arguments onto stack

visual-c++,assembly,macros
I've been working on a fun little project to mess around with how functions are called and I need a macro to push arguments as it'll be quite time consuming to push the arguments manually for every instance of this obfuscated call. This is my code so far: #define pushargs(...)...

x86 jmp asterisk %eax

assembly,x86,jmp
In the paper for Google Native Client, the authors define a nacljmp as these two instructions: and %eax, 0xffffffe0 // Clears the 5 least significant bits in %eax. jmp *%eax First, I can see they clear the 5 least signficiant bits to make the instruction 32 bit aligned before it...

Hybrid program (.asm + .cpp): modify small math program's code to include float input

c,assembly,floating-point,hybrid
(Intel x86. TASM and BorlandC compilers, and TLINK used.) In main1.cpp the program takes int input (until you input a number smaller than -999999), puts it into an array x[], puts the number of inputs into array's 0th element, sends array's pointer to f1.asm, adds the numbers, and returns the...

Assembler plump/water animation

assembly,nasm,interrupt,ms-dos
I am new in assembler and I am looking for easy solution how to insert a loop in my code. Can you guys give me a tip or answer? I found some articles on google and I cannot understand them cuz I am dumb, though. I've to do a projeckt:...

Open Watcom Inline assembly SEG and OFFSET operators

c,assembly,memory-address,watcom
Today, I have learned that the SEG operator in MASM by default returns the address of the GROUP and not the address of the SEGMENT of the expression in question, and that there are options and methods to override that. Since I am currently doing a complex project in Open...

Encode in machine code an Assembly MIPS instruction

assembly,mips
I need to encode the following beq instruction: ... start: addu $8, $9, $10 addiu $8, $8, 0x00FF7A01 beq $8, $0, start ... I know that it is a J format instruction so the division will be 6 bits to opcode and 6 to target address. beq opcode is 000100,...

Counter not working after jumps - assembly language

loops,assembly,counter,increment
For some reason, when i switch to mouse input switch back to keyboard input for my program, increasing and decreasing the counter has no effect. It works perfectly in the first loop where we input characters. Here is the program guys, any advice? look at whatspeed jump for reference after...

C Kernel - Works fine on VM but not actual computer?

c,assembly,operating-system,kernel,hex
I am making a basic C kernel. (Loaded by an assembly program) I am compiling it with an i686-elf cross compiler for windows. My C code is as follows: void cls(); void drawhappy(); void main(){ char *vidptr = (char *)0xb8000; cls(); drawhappy(); } void cls(){ char *vidptr = (char *)0xb8000;...

FASM: Calling Tangent from GCC

gcc,assembly,fasm
I don't know what the problem is because this works perfectly for SIN and COS. For TAN, it returns 0.0000 for 50.0 radian. But if I enabled the commented line, it works as expected. That's weird because TAN is supposed to return a double in XMM0, not RAX. ;./fasm testing.asm...

NASM assembled bootloader memory issue

assembly,nasm,bootloader
I am writing a bootloader with nasm. At the moment it is designed to output a welcome string, then record keystrokes while displaying them, printing the stored keystrokes upon finding the enter key, and finally halting. bits 16 org 0x7C00 start: jmp main bgetkey: pusha mov ax, 0 mov ah,...

Read bytes from Dump in Masm

assembly,masm32
In one part of my application i need read a bytes invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT, eax; eax = size mov hMemory,eax invoke GlobalLock,hMemory mov pMemory,eax How can "move" the first 4 bytes of pMemory to eax?? and later move the next 2 bytes to ebx?? Example: 1A5288.... 12 34 56...

Assembler debug of undefined expression

c,assembly,undefined,x86-64
I'm trying to get a better understanding of how compilers produce code for undefined expressions e.g. for the following code: int main() { int i = 5; i = i++; return 0; } This is the assembler code generated by gcc 4.8.2 (Optimisation is off -O0 and I’ve inserted my...

Subtraction order in assembly

assembly,x86,calling-convention,att
So I have. pushl %ebp movl %esp, %ebp movswl 12(%ebp), %edx movl 8(%ebp), %eax subl %edx, %eax popl %ebp ret If say my function calls 2 variables: function(int a, short b). When I call the subtraction, would it be (b - a) or (a - b). eax is where the...

Address Out of range mips

assembly,mips
Hello i am trying to implement the mccarthy 91 function in assembly code. When i run my code it assembles with no errors but when i enter a value for n the program gets runtime exception address out of range. I've looked over my code and i cant find out...

Assembly unknown mnemonic AArch64 ARMv8

gcc,assembly,cross-compiling,arm64
I'm trying to compile a project (from GitHub: link) with a couple of assembly files, which are written for the ARMv8 AArch64 architecture. When I try to compile these files I get the same error on pretty much every line, it starts with: authenc_ac_gcm_low.S: Assembler messages: authenc_ac_gcm_low.S:80: Error: unknown mnemonic...

storing array from user and accessing it

arrays,assembly,input,user,mips
I have to create an int array based on user input, sum the integers, and output the sum and the array itself. My code calculates the sum correctly, but I cannot output the list. It only prints out the last number and zeros and then gets stuck in an infinite...

Is this an overflow, or maybe more keyboard data?

assembly,nasm,bootloader
I am writing a bootloader, and it's functionality is basically limited to printing a string, then copying keyboard characters to the screen as they are typed. While writing the routines that read and write the key, I noticed my print routine was not detecting the null terminator in offset (plus)...

Range of Addresses for a Conditional Branch Instruction in MIPS

assembly,mips
What is the range of addresses for a conditional branch instruction in MIPS with respect to X, where X contains the address of the branch instruction? Assume the current PC value is 0x10000000. What is the range of addresses for jump (j) and the jump and link (jal) in- structions...

about GDT and processes

c,assembly,operating-system,protected-mode
how does GDT reflected on linear space of process ( if I understand it right, GDTR contains page and offset ) .? or another version of this question : GDTR is unique for each process .?

Hybrid program (asm+cpp): sending and receiving an array pointer

c++,pointers,assembly,offset,hybrid
(Intel x86. Turbo Assembler and BorlandC compilers, Turbo Linker.) My question will be about how to modify my f1.asm (and possibly main1.cpp) code. In main1.cpp I input integer values which I send to function in f1.asm, add them, and send back and display the result in main1.cpp. main1.cpp: #include <iostream.h>...

Reserve bytes in stack: x86 Assembly (64 bit)

assembly,x86-64,cpu-registers
pushq %rbp movq %rsp, %rbp subq $32, %rsp I have big question regarding explanation of "$32" in third instruction. The information from search and blogs specifies that in above third instruction we are reserving certain "bytes" of space for stack. From doc, %rsp is 64 bit register and %esp is...

How should the byte sequence 0x40 0x55 be interpreted by an x86-64 emulator?

assembly,x86-64
I'm working with an emulator, and one of the binary executables I've run across has the following sequence in the beginning of a procedure 40 55 The 40 is a REX prefix, but none of the REX bits are actually set. Section 2.2.1.7 of the Intel software developer's manual states...

Assembly 8086 addressing mode

assembly,8086,addressing-mode
How does XOR [130][BX][DI], CL work? (I know what XOR does) I mean how is the effective address of the memory part calculated? Which addressing mode is this?

How is shellcode generated from C? - With code example

python,c,gcc,assembly,shellcode
I started taking an online course regarding software security. In one of the sections, I was instructed to execute a hidden C function using a buffer overflow. I got to thinking: what would happen if I could pass machine instruction directly to a stack unsafe executable? What I have been...

NASM: copying a pointer from a register to a buffer in .data

linux,assembly,nasm,x86-64
I am new to asm. I am trying to copy a pointer from a register to a .data variable using NASM, on linux 64-bit. Concider this program: section .data ptr: dq 0 section .text global _start _start: mov [ptr], rsp mov rax, 60 mov rdi, 0 syscall Here I try...

Wrong answer from DIV assembly

assembly,x86
I have a part of my code mov di,3 mov cx,16 looop: xor dx,dx shl bx,1 adc dx,dx cmp cx,16 je cx16 (it's will dec cx and jump loop) push dx dec cx cmp cx,0 je cx0 mov ax,cx div di cmp dx,0 jne looop when cx = 3 i...

SHR and SAR Commands

assembly,masm
I would like to make sure I am understanding this concept 100% and if not get some clarification. In an asm program, if you perform SHR 00110000b you would end up with 00011000b. However, if you were to perform SHR on 11111111b you would end up with an incorrect answer...

Defining segments of assembly code with Tasm

assembly,tasm
So I was being taught the basics of how to program with Tasm (Turbo assembler 16 bits) and this two lines were explained to me, but now I can't remember why are they like this: start: mov ax, data mov ds, ax Why is it that we cannot use: start:...

Perform integer division using multiplication

assembly,optimization,bit-manipulation,division,multiplication
Looking at x86 assembly produced by a compiler, I noticed that (unsigned) integer divisions are sometimes implemented as integer multiplications. These optimizations seem to follow the form value / n => (value * ((0xFFFFFFFF / n) + 1)) / 0x100000000 For example, performing a division by 9: 12345678 / 9...

2 bit right shift of a 32 bit unsinged integer with special conditions in assembly.

assembly,binary
I just had my "Langage de Programmation" exam, which was about knowledge and use of assembly code. One of the questions asked this and I was unsure what the answer should have been: Let N1 be an unsinged integer over 32 bits. Give the assembly code allowing to realise the...

(Assembly 8086) How can I return from a function to a different segment?

assembly,stack,stack-overflow,8086
I got an assigment to write to programs. One which gets input from the user, using a function that allocates a string on the stack, and writes to it, one character at a time, until it gets an "Enter". And another program that uses the flaws of the first one,...

How do I check assembly output of Java code?

java,assembly
I found this question that answered it for C++: How do you get assembler output from C/C++ source in gcc?

Does int 80h interrupt a kernel process?

c,linux,assembly,linux-kernel
First some background knowledge, this is from the book: Linux System Programming: Talking Directly to the Kernel and C Library Signals are a mechanism for one-way asynchronous notifications. A signal may be sent from the kernel to a process, from a process to another process, or from a process to...

PORT Mapping, Memory Mapping

assembly,embedded,microcontroller,firmware
Can any one explains me clearly, what is mapping? Port mapping? Memory mapping? In firmware development. I gone through many other sites, still the question is not clear. Asked in an interview for Firmware Developer. The actual question is "How does you access data holding in the register/memory of a...

converting a vector of chars to int in assembly

assembly,x86,8086
I'm trying to do the following, but I'm having some trouble, and the only code I find on the web is for transforming strings into a number (basicly atoi), but I need something slightly different, e.g: num1 Db '60','30' num2 Db '2', '3' num3 Db '*', '*' Basicly I only...

Switch to user space

assembly,x86,operating-system,kernel
this is part of code which demonstrates basic functions of os kernel. After flushing GTD and setting up IDT I want to switch to ring 3 run some int and context switch. However I cannot jump to user mode. I want to use trick with iret instruction. As far I...

Declaring Variables in the .data Versus on the Stack - ASM

assembly
I'm trying to understand in which cases you would want to declare variables in the .data section of my assembly program and using it for the procedures needed, over instantiating local variables on the stack and vice versa. Is it just that declaring variables in the .data section is only...

Understanding NASM Macro

assembly,macros,ffmpeg,nasm
I've come around this macro in a assembly source file and I just can't figure out how it's working. So first I come around this function (hevc_deblock.h): cglobal hevc_v_loop_filter_chroma_8, 3, 5, 7, pix, stride, tc, pix0, r3stride sub pixq, 2 lea r3strideq, [3*strideq] mov pix0q, pixq add pixq, r3strideq TRANSPOSE4x8B_LOAD...

Why does main function differ from other function from stack point of view

c,assembly,operating-system,stack-trace
I'm studying to use gdb and i got little confused. Here is my code: #include <stdio.h> #include <stdlib.h> #include <string.h> void g(char *password) { } int main(int argc, char *argv[]) { if(argc > 1) { g(argv[1]); } } So with the regular function (g() in this example) if I want...

x64 program returns the correct SIDT value occasionally (x64 assembly)

c,visual-studio-2012,assembly,64bit
I use Visual studio 2012 and I created a x64 bit program that returns the value of the SIDT function (without the offset). The problem is that when I initially run the program, it returns the right value, but when I run the program multiple times, it returns the right...

MASM console window creation troubles (maybe my stack frame??)

winapi,assembly,stack,x86-64,masm
I'm having trouble with the following code snippet. I'm compiling an asm file with a c++ file using visual studio express 2012. I've tried debugging calculating the addresses of the stack pointers and memory locations (still learning assembly obviously), but can't find a fault. (As I'm new it's probably something...

GCC compile and link raw output

gcc,assembly,mips
I am trying to get the raw instruction code output for a simple C program with function calls. I have already searched on here and Google for the answer but can only find answers that are correct for single functions (no function calls). A trivial example: int main(){ return addition(5,...

How is a file loaded in the FAT file system?

filesystems,fat32,assembly
I am developing a bootloader in x86 Assembly and I have a question about the FAT file system. Which steps are necessary to find and load the file?...

Swap the two middle bytes of a word using 4 ARM instructions

algorithm,assembly,arm
The task is to write code in arm assembler using no more than 4 instructions that swaps the two middle bytes in a given 32-bit word. For example if the word is 0xAABBCCDD the result should be 0xAACCBBDD. You may use at most 4 arm instructions from the set AND,...

How to find illegal instructions in a program?

c++,c,assembly,gdb,benchmarking
I have a benchmark which is meant to run on a specific simulator, Some instructions where added to the benchmark to communicate with the simulator(not perform CPU operations), like dump stats or reset stats and so on. Now I need to run the same benchmarks on another simulator, and there...

NASM: Makefile for library

assembly,makefile,nasm
I'm having trouble building a makefile for a library in nasm, since it requires that you run nasm with one input file at a time. I have tried with the %.o : %.s thing but I'm probably doing it incorrectly since it's not working. Here is what I have: NAME...

Print a number in NASM - building an x86 Bootsector

assembly,nasm
I just started messing around with assembly language and I tried to print the number 9 on console. Here is what I wrote: global _main section .data digit equ 9 section .bss section .text _main: mov edx, 1 mov ecx, digit add ecx, 48 mov ebx, 1 mov eax, 4...

Print string using INT 0x10 in bootsector

assembly,x86,fasm
I want to create printl function that allow me to print string in the ax register. I am in 16-bit real mode and I can not find any way to print a message. I using int 0x10 to print a single letter. I try pass argument (string to print) in...

print the 10th characher image on command line with assembler

assembly,codepages
The question is how to make command line show 10th charachter image (not new line feed). I've tried this code (using TASM): .model tiny .code org 100h begin: mov ah,2 mov dl,10 int 21h ret end begin And here is the output (just new line feed): I want to display...

Play a sound file in masm32 and to stop the other sound file at the same time [closed]

winapi,assembly,x86,masm32,playsound
So I am doing a game in assembly language and I am using the PlaySound() function to play a background song. I want to do that after I "die" in the game, another sound file will start playing a sound file, and at the same time will stop the other...

puts implementation in assembly with nasm x86-64

assembly,nasm,x86-64,puts
I'm new to assembly and I'm trying to work on an implementation of the C function puts in assembly with nasm x86-64 on my Ubuntu. Everything was fine until I write the tests for the function: there is a behavior that I can not reproduce: When I send char *str...

Why Masm32 only give 1 to 100 result for add and subtraction operation and beyond that I got wrong answer?

assembly,masm32
I am new to assembly language. I make this code just now and run it with no errors so far, except It will only give a result from 1 - 100, here's my code. This is a simple math operation which is addition and subtraction. I tried analyzing the code...

Could this shift/jump be faster than switch…case statement?

assembly,x86,switch-statement,emulation,opcodes
I'm trying to optimize a branch (a switch...case like) at its max to emulate an X CPU on an x86 CPU. I thought of this: In memory I'll load blocks of x86 opCodes with a fixed length of 0x100 bytes, like this: first block 0 ...[my code, jump at 0x10000,...

Pong project in assembly 8086

assembly,8086,pong
I have a problem in my pong project. I try that when the ball hits the red bat it will randomly bounce back to the other side, but from some reason it does not recognize the red color. I use AH = 0Dh in int = 10h. The part of...

SIMD minmag and maxmag

assembly,floating-point,x86,sse,avx
I want to implement SIMD minmag and maxmag functions. As far as I understand these functions are minmag(a,b) = |a|<|b| ? a : b maxmag(a,b) = |a|>|b| ? a : b I want these for float and double and my target hardware is Haswell. What I really need is code...

Asm x86 segmentation fault in reading from file

assembly,x86,segmentation-fault,mmap
I'm receiving segmentation fault in 5th line of loop2. This is the part of my code which is reading values from mmapped file byte by byte. Could you please tell me what I'm doing wrong? .global _start _start: mov $2,%rax mov 16(%rsp),%rdi mov $02,%rsi syscall cmp $0,%rax jl exit 1:...

Error: Junk at EOL, first unrecognised character is '('

assembly,gas,quake
I am trying to compile Quake 1 (QW) from source code and have run into the following problem when compiling client/d_copy.s : Error: Junk at EOL, first unrecognised character is '('. The file in question is here (please excuse the syntax highlighting, pastebin only supports NASM). I am attempting to...

Program solving equation in Assembly

assembly,equation,tasm,dosbox,operands
I have problem with my simple program in assembly. I'm using DOSbox and TASM . I have problem with program. Operand types do not match at line 76 78 80 . This is after multiplication. I tried to make some changes by using difftrent variable size ; -------------------------------------------- ; Equation=(a+c*b)/d-2*c,...

Why can't I use compiler intrinsics in an asm block?

delphi,assembly
Is this a compiler bug? program Project44; {$APPTYPE CONSOLE} uses System.SysUtils; function Test: integer; asm xor eax,eax add eax,SizeOf(NativeInt); end; begin WriteLn(Test); //Typically outputs 31 or 49 {$ifdef CPUX86} WriteLn('should be 4'); {$else} {$ifdef CPUX64} WriteLn('should be 8'); {$endif}{$endif} ReadLn end. This program outputs all kinds of things, except for...

Type character and print its code with Assembler

assembly
I am trying to print the code of character(in latin) that has been typed in console. Here is my code (using TASM): .model tiny .code org 100h begin: mov ah,01h int 21h or al,30h mov ah,2 mov dl,al int 21h ret end begin But that doesn't work, see the screenshot...

x86 asm - 12 bytes subtracted from esp. Only 8 needed

gcc,assembly,x86
I've compiled this code with gcc (gcc -ggdb -mpreferred-stack-boundary=2 -o demo demo.c) and decompiled it to look at the assembly (I know it's using unsafe functions, this was for an exercise into buffer overflows): #include<stdio.h> CanNeverExecute() { printf("I can never execute\n"); exit(0); } GetInput() { char buffer[8]; gets(buffer); puts(buffer); }...

How to represent mips instruction as it's hex representation

assembly,mips
I'm given a MIPS instruction: top: lw $t1, ($t0) beq $s0, $0, end jal func add $s0, $s0, $t0 addi $s0, $s0, -1 j top bne $s0, $0, top end: func: sll $v0, $t1, 4 jr $ra and am told to convert each line to the "instruction in hex." What...

xmm, cmp two 32-bit float

assembly,floating-point,sse
I'm trying to understand how to compare two floating point numbers (32-bit) using the xmm registers. To test I've written this code in C (which calls the code in assembly): #include "stdio.h" extern int compare(); int main() { printf("Result: %d\n", compare()); return 0; } Here is the assembly, I want...

What's the asm equivalent of replacing a char from a string to a char of another string?

assembly,nasm,x86-64
I'm trying to code strcat to learn assembly. I code on mac osx with nasm using 64 bit assembly, with Intel syntax. Here's my result so far : section .text global _ft_strcat _ft_strcat: mov rax, rdi mov rbx, rsi loop_s1: cmp byte[rax], 0 jz copy_str inc rax jmp loop_s1 copy_str:...

square brackets in inline assembly

c,assembly,inline-assembly
I try to use lea rax, [rip] in a c program. My program is following: ... asm volatile ("lea %%rax, %[rip]" :); ... However, the program does not compile, throwing an error: undefined name operand. My platform is Ubuntu 1404 on a x86-64 architecture (as virtual machine)....

DB ASM variable in Inline ASM C++

c++,assembly,inline-assembly,ms-dos,borland-c++
I'm trying to figure out how to use DB variables from ASM into Inline ASM C++ I have this ASM code: filename db "C:\imagen.bmp" eti0: mov ah,3dh mov al,0 mov dx,offset filename int 21h and in C++: //ASCII of C:\imagen.bmp plus zero in the end because of int 21h int...

Make the input wait for mouse or keyboard - Assembly Language

assembly,input,keyboard,mouse,simultaneous
I fixed my program, but now the loop seems to be stuck. Whenever I press u or d, it is stuck, but the mouse part works :) ; You may customize this and other start-up templates; ; The location of this template is c:\emu8086\inc\0_com_template.txt org 100h CLEAR MACRO MOV AX,0600H...

NASM: in/out instead of int

assembly,nasm
When writing a bootloader how do you make calls to ports instead the use of interrupts (i.e. int 10h)? Is there a list someplace online I am unaware of for known vectors? Is there a place I can go to do mapping of hardware not covered by the bios interrupts...

Using Assembly global variable in C

c,assembly,makefile,global-variables
Trying to compile this code in a.s: section .bss global _start global TestVar TestVar: RESB 4 section .text extern main _start: and this code in b.c: extern int TestVar; void test2(int x, int y) { int z = TestVar; x = z + y; y = 1; } int main(int...

How can I access the individual elements of an array in a loop?

assembly,mips
I need to print the cells of an array, I have an array which contains the word "HELLO_WORLD", I manage to print an index by its own but I can't manage to print all the cells one by one, here is the code : loop: la $t0, hexdigits # address...

Reversing a string and printing it in IA32 assembly

string,assembly,x86,att,reversing
So basically I'm trying to read a string, increase a counter (in this case, %edx) until I read a \n, and then, going backwards to print it reversed. This is my code: .section .data cadsal: .asciz "Por favor ingrese su cadena:\n" leer: .asciz "%s" salidafinal: .asciz "La cadena introducida, invertida...

Using gas, how can I get the offset to a particular label?

assembly,gas
I'm using pwnlib to write a small shellcode for a challenge. My shellcode needs to modify itself to pass application filters. I first wrote it with nasm, and did something like that: sub edx, edx mov dl, 0x82 add al, do_mov_rdi_rax sub dword [rax], edx mov dh, 0x82 add al,...

MinGW's ld cannot perform PE operations on non PE output file

gcc,assembly,mingw,nasm,osdev
I know there are some other similar questions about this out there, be it StackOverflow or not. I've researched a lot for this, and still didn't find a single solution. I'm doing an operative system as a side project. I've been doing all in Assembly, but now I wanna join...

Meaning of this set of instructions in Mic-1 [MAL Language]

assembly,cpu-architecture,microcoding,mal
The sequence of Mic-1 instructions below realize a new instruction bish8pu x (x is an offset in 8 bit in binary code). What is the meaning of this set of instructions? bish8pu1 MAR=SP bish8pu2 H=TOS << 8 bish8pu3 TOS=MDR=MBRU OR H;wr bish8pu4 PC=PC+1;fetch bish8pu5 goto Main1 Thanks a lot...

CALL function in assembly

assembly,push,esp
I have a question about a CALL function in a assembly code. Is it right when I execute a CALL function in assembly that the instruction is pushed onto the stack? When is the instruction popped back when I CALL a function?

Range of immediate values in ARMv8 A64 assembly

gcc,assembly,arm64
My understanding is that immediate parameters in ARMv8 A64 assembly can be 12 bits long. If that is the case, why does this line of assembly code: AND X12, X10, 0xFEF Produce this error (when compiled with gcc) Error: immediate out of range at operand 3 -- `AND X12, X10,...

Setting a float/double to a constant value in AT&T inline assembly

c++,c,gcc,assembly,inline
I'm looking at increasing the runtime performance of a C++ library that I have written and profiled. I'm very new to assembly (and inline assembly) and have a very basic question to ask. How do I set the value of an xmm register (xmm, ymm, zmm, etc) to a constant...

ARM assembly cannot use immediate values and ADDS/ADCS together

gcc,assembly,arm,instructions
I am currently trying to speed up some of my C functions on a Cortex-M0 (Freescale KL25Z) using assembly. I get a problem with this minimal test program: @.syntax unified .cpu cortex-m0 .text .global test .code 16 test: mov r0, #0 adds r0, r0, #1 bx lr When I try...

subl causing Floating point exception

assembly,x86
I am creating a compiler which should compile a fictional language into asm x86 code. When compiling this piece of code (fictional code): int x; int f(int n) { write n; } int main() { x = 1; f(x); } write is equal to just print in console. The desired...

How does this instruction look in memory?

assembly,x86
I am having trouble figuring out how this instruction looks in memory for a x86 processor. mov $0x3c,%eax Can someone help me figure it out? For example an easy one is: xor %edi,%edi ---> 0x31 0xFF...

Assembly - Moving Floating Point Number

assembly,floating-point
I am new in Assembly, I did a lot of searches before asking this but I quite could not understand/find anything I am looking for. fstp dword ptr [eax+00000124] I have this line, so how do I edit it to store any floating number on [eax+00000124], e.g. storing number 6...

C float in NASM x86 assembly

c,assembly,x86,nasm
In my university project i have to use binary representation of float number in x86 assembly for arithmetic operations. Using FPU is forbidden so i try to read float number and return it as DWORD but whatever i try to do i get "-nan". Any advices? Edit: I use gcc...

GCC emits vastly different code using “-march=native” on similar architectures

c,gcc,assembly,sse,avx
I'm working on writing an OpenCL benchmark in C. Currently, it measures the fused multiply-accumulate performance of both a CL device, and the system's processor using C code. The results are then cross checked for accuracy. I wrote the native code to take advantage of GCC's auto vectorizer, and it...

What does DX + 2 mean in mov ah,9 int 21h?

assembly
mov dx, offset buffer mov ah, 0ah int 21h jmp print buffer db 10,?, 10 dup(' ') print: xor bx, bx mov bl, buffer[1] mov buffer[bx+2], '$' mov dx, offset buffer + 2 mov ah, 9 int 21h I know buffer[bx+2] stands for '$', but offset buffer +2 in mov...

How to jump to an address saved in a register in intel assembly? [duplicate]

assembly,jmp
This question already has an answer here: conditional jump to register 1 answer say I calculated an address of a label and stored it in eax register, how can I JMP(specifically JE) to eax? jmp eax compiles, but I didn't check if it works. je eax doesn't compile(invalid combination...

nasm: jump when input is NULL

c,assembly,nasm,libc
I am recoding puts using nasm (64bit), and when puts receives NULL as argument it prints (null). I'm trying to recreate that behaviour, except I can't get the code to jump to the part where it prints (null). Instead it just prints nothing here's my code: global _my_puts section .text...

Linux AMD64 call C libary functions from copied assembly

c,linux,assembly,x86-64
How do I call from an memcpy'ed assembly function a C library functions? I'm making an example test code how one can allocate and change memory protection on Linux, AMD64 to run arbitrarily generated code from C. What I done is that I compile an small GAS assembly function along...

LC3 assembly-how to count string length

string,assembly,lc3
I am trying to create a program at LC3 assembly that counts the length of a string in the following way: All data is already stored somewhere in memory. There is a variable in which the address of the first element of the string is stored. (I apologize in advance...

nasm, macro print not working

c,assembly,macros
I'm calling a function written in assembly from a C file. The c code passes two pointers to the assembly function. I'm using the print macro into the assembly to check the value of the addresses and of the elements pointed by them. Here is the C code: extern int...

how stack differs in 32 bit and 64 bit processors

c,assembly,gdb,disassembling
i disassembled the following code in gdb for both 32 bit and 64 bit intel processors. void main() { 5 char *args[2]; 6 7 args[0] = "/bin/sh"; 8 args[1] = NULL; 9 execve(args[0],args,NULL); 10 exit(0); 11 } Following are the assembly code generated. For 64 bit Dump of assembler code...

IA-32 assembly: Effect of 8 bit operations on 32 bit registers

assembly,ia-32
During a course in computer science one gave me a binary file and the task to find out what it does, using the technique of reverse engineering (i.e. disassemble the file and analyze it). I stumbled upon one line of IA-32 instruction: add %esi,%ecx I learned that commands with suffix...

Visual Studios building and debugging .cpp file without main()

c++,assembly,visual-studio-2013
Professor just gave us a block of c++ code in order to learn about the debug windows in Visual Studio, however after creating a blank win32 console project and then dragging in the .cpp file I get the missing .exe error message when attempting to debug. I've looked everywhere and...

assembly function with C segfault

c,assembly,x86,sse,fpu
I am trying to make assembly function that uses SSE and FPU for parallel calculations. Unfortunately I am receiving segmentation fault(core dumped) error(while debugging it doesn't show in assembly function). I also cannot step out from assembly function. Gdb shows: Warning: Cannot insert breakpoint 0. Cannot access memory at address...