assembly

Understanding Assembly

I've got some assembly of a sorting algorithm and I want to figure out how exactly it functions. I'm a little confused on some of the instructions, particularly the cmp and jle instructions, so I'm looking for help. This assembly sorts an array of three elements. 0.00 : 4009f8: 48 8b 07 mov (%rdi),%rax ...

How did 16-bit C compilers work?

C's memory model, with its use of pointer arithmetic and all, seems to model flat address space. 16-bit computers used segmented memory access. How did 16-bit C compilers deal with this issue and simulate a flat address space from the perspective of the C programmer? For example, roughly what assembly language instructions would the f...

How to calculate DS:[0040207A] manually?

How to get the result 77D507EA manually from DS:[0040207A] according to register info above? UPDATE ...

Hex values of registers? x86

MOV DL,AL "MOV DL" = B2 But what is the hex byte value for AL? Where are these listed? I just realized it must be another opcode! Can anyone point me in the right direction? ...

How to generify data for "mov" instruction ?

Hello, I need to understand just 1 single instruction and accordingly I need to generify the things. I need to pass structures (Objects of User Defined Data Types) at runtime using following assembly code. Where Following is User Defined Data Type namely WESContext : typedef struct CWESContext { BSTR UserName; BSTR Mach...

C++ static variables question

Hello! I was recently interested in how does Microsoft Visual C++ compiler makes and optimizes static variables. I have the following code: void no_static_initialization() { static int value = 3; } void static_initialization(int new_value) { static int value = new_value; } #include <cstdlib> int main() { no_static_initiali...

What's the most accurate way of measuring elapsed time in a modern PC?

I know I can use IRQ0, which is the system timer, but this is based on a 14.31818MHz clock, right? Is there anything offering greater precision? Thanks. Edit: Does anyone know what the Windows function QueryPerformanceCounter uses? ...

How to import a function from libc6 into an ELF executable?

I am creating an i386 ELF executable that needs to import a function from libc6. (It's printf, by the way.) I have created a very small ELF executable that prints "Hello, world!" to the console by using the Linux kernel interrupt 0x80. This is not optimal and I would like to have the application make use of libc instead. Here is what I...

assembler write to file problem

dseg segment FileName db "hex.txt$" dseg ends cseg seg.. ... wrFile proc push ax bx cx dx mov ax,3D00h mov dx, offset fileName int 21h mov bx,ax mov cx,10*type scores mov dx,offset highscoresnum mov ah,40h int 21h mov dx,offset highscoresdate mov ah,40h int 21h mov ah,3eh int 21h pop dx cx bx ax ret wrFile endp at the f...

My memory stack confusion i.e. Push and pop insturction

Hello, I'm little bit confused with one thing about memory stack. From what I know a stack is created for process/thread in higher address memory and continues to lower addresses. Now the problem part. When you Push something on stack it first decreases address and then stores something on stack. Isn't there some memory lost because Pus...

How do I load my program into a specific location in memory?

Hi Guys , I have a assembly language code ,I want to put it into a particular location at memory.The idea is basically when I finish running a code it jumps to the memory location where my other program is stored.So.what instruction/assembler directive I use to put it the desired memory location? ...

Assembly Language kernel

I am trying to write a kernel purely in assembly language. How do i go 'bout the development environment and general setup that lets me control what i want it to do? ...

[ASM] MASM compare uninitialized buffers

Hello everybody, I'm stuck writing my program Here's what I wanted it to do: display a welcome message inside a console Wait for the user to imput a number from 0 to 9] compare that number to 0 display a message if it is, else exit Here is what I currently have: .386 .model flat,stdcall option casemap:none include \masm32\include\wi...

Using assembly routines with C on DOS

Hello, I've been playing with DOS real mode assembly for a while and now I want to utilize some routines in a C program. I'm using Turbo C 2.01 and TASM 3.0. I'm however unable to modify a variable passed by address, see the _setval routine below. I don't need/want inline assembly. A simple example: foo.c #include <stdio.h> extern voi...

32-bit Linux Assembly - Linking files together (gas and ld)

I wrote a function called strlen: .section .text .global strlen .type strlen, @function strlen: ... code ... I assembled this like so: as --32 strlen.asm -o strlen.o Then I wrote a program in asm to print argv which I want to link with this. I assembled that the same way. Now I want to link them together so that the actual program ...

movq assembly function

I was reading some code and was not sure what this line does movq (%rsp), %rsp Thanks ...

Printing Hexadecimal Digits with Assembly

I'm trying to learn NASM assembly, but I seem to be struggling with what seems to simply in high level languages. All of the textbooks which I am using discuss using strings -- in fact, that seems to be one of their favorite things. Printing hello world, changing from uppercase to lowercase, etc. However, I'm trying to understand how t...

How is Assembly used in the modern day (with C/C++ for example)?

I understand how a computer works on the basic principles, such as, a program can be written in a "high" level language like C#, C and then it's broken down in to object code and then binary for the processor to understand. However, I really want to learn about assembly, and how it's used in modern day applications. I know processors ha...

How do I atomically swap 2 ints in C#?

What (if any) is the C# equivalent of the ASM command "XCHG". With that command, which imo is a genuine exchange (unlike Interlocked.Exchange), I could simply atomically swap two ints, which is what I am really trying to do. ...

Memory corruption in assembly?

I currently have an assembly program which is modeled after the hexdump system function in Linux. Essentially, it prints the current line number, converts the binary values to hexadecimal strings and also shows the current ASCII associated with the hexadecimal string. I'm experiencing a problem with my system of printing line numbers. T...