Hey
I'm learning assembly (low level only for now) on my linuxbox.
Could someone convert the following c++ to asm(low level) so i can learn how to do math operations?

#include <iostream>
using namespace std;

int main() {

int a = 10;
int b = 12;

cout<<a+b<<endl;

}

Of course the variables don't have to be the same, and it has to be for linux.

Thanks

g++ -S prog.cpp

Now go look at prog.s to see the assembler.

Ok, thanks. Now to go through all the code, and try to understand it enough to make a smaller version.... it looks complicated:S

Update: It's way to complicated (for me) to read all that code, and it looks like I won't find a way to add, and print something to the screen with it.

If I could figure out a way to convert a number to a string (from registers) I could print it out with the linux call 4. Any ideas?

Ok, I think for the call 4 to work it needs to be a string so here is what I got:

format ELF executable
segment readable writable
	a db '5'
	b db '10'

segment writable
	entry start

start:
	mov eax, 4
	mov ebx, 1
	add ecx, a
	add ecx, b
	mov edx, 2
	int 0x80

	mov eax, 1
	mov ebx, 0
	int 0x80

No output... (compiled with fasm)

Hello?
Using fasm could I do something using the "IN" comand and the "OUT" command.

Unless you're writing a driver for the OS, no.
Access to the hardware in Linux is a priviledge which normal programs don't have.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.