help in program ( assembly language )


.
Last edited on
Which is it? Assembly or C?
assembly language in c++
Last edited on
Do you mean inline Assembly?
here is an example of this language:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
char get1[] = "Give me the first number:";
char get2[] = "\nGive me the second number:";
char same[] = "\n Numbers are equal\n";
char notsame[] = "\n Numbers are not equal\n";
char format[] = "%d"; // format string for the scanf function

int first;
int second;

_asm {
lea eax, get1; ask for the first number
push eax
call printf
add esp, 4

lea eax, first; read it in
push eax
lea eax, format
push eax
call scanf
add esp, 8

lea eax, get2; ask for the second number
push eax
call printf
add esp, 4

lea eax, second; read it in
push eax
lea eax, format
push eax
call scanf
add esp, 8

mov eax, first
cmp eax, second; compare the numbers

jl less; jump if less than

jg greater; jump if grater than

jne nequal; jump if different

lea eax, same; come here if numbers the same
push eax
call printf; printing "Numbers are equal"
add esp, 4
jmp finish; all done

less : lea eax, less; //come here if 1st is > 2nd
push eax
call printf; printing "first number are greater then the second number"
add esp, 4
jmp finish; all done

greater: lea eax,greater; //come here if 2nd is > 1st
push eax
call printf; printing "second number are greater then the first number"
add esp, 4
jmp finish; all done

nequal : lea eax, notsame; come here if numbers differ
push eax
call printf; printing "Numbers are not equal"
add esp, 4

finish:
}
return 0;
}



closed account (L307fSEw)
COMP103 Assignment 3, shocking to see this online.
Topic archived. No new replies allowed.