New to Assembly language, reading a book here. I'm trying to do an simple basic exercise. Using appropriate registers, I have to add 100, 200, 300, 400, 500. Don't know where to start with this program. This is the outline of the program, now I need to add the registers. This is what I have, from what I understand from the book. Don't know how to keep adding.
(AddSub.asm) INCLUDE Irvine32.inc .code main PROC mov eax, 100 add eax, 200 exit main ENDP END main 33 Answers
If you have experience with higher level languages like C, then these lines:
mov eax, 100 add eax, 200 Would do something akin to:
int eax; eax = 100; /* mov 100 to EAX */ eax = eax + 200; /* add 200 to EAX */ If you want to add other numbers you keep adding to EAX like:
add eax, 300 add eax, 400 You can use other registers besides EAX (like EBX,ECX,EDX,ESI,EDI). You can also add these registers together. For example
mov eax, 100 mov ebx, 200 mov ecx, 300 add eax, ebx add eax, ecx This would be akin to:
int eax = 100; int ebx = 200; int ecx = 300; eax = eax + ebx; /* add EBX to EAX */ eax = eax + ecx; /* add ECX to EAX */ Which would result in a value of 600 in EAX
Using Irvine32 library you can print the contents of EAX as a signed integer by calling the WriteInt function like so:
call WriteInt 3Just add more add instructions:
add eax, 300 add eax, 400 add eax, 500 You also have to print out the result somehow, before your exit line.
I think you should keep adding add the numbers to the eax register right after the mov instruction. From the little i know this is what the eax is for.
section .text global __start __start: mov eax, 100 add eax, 200 add eax, 300 add eax, 400 add eax, 500 ; you can print it out here mov eax, 1 Int 0x80 I hope this helps.
3