I want to write my first assembly program. I have done some programs on papers but its my first time with the compiler. I am using ideone. My program is very simple,
Translate A = 5 - A to Assembly
NEG A
ADD A, 5
Now I want to run this program and check it. How do I do it with the compiler? Please help me out. Thanks
This is not quite valid 8086 assembly language. At least, it’s not in any assembly syntax that i’m aware of.
Ais a memory location, you need a label for it somewhere. And you need to let the assembler know that it’s supposed to be a word pointer, since you’re not putting it in a register. (The register size can make the pointer semantics obvious, but you’re not using registers here. :P)The corresponding 8086 code (which is quite similar) would be
Or, for memory:
(MASM can sometimes do without the brackets. I don’t know MASM syntax, so hopefully someone else can clear that part up. Oh, and it’s not the way pretty much every other assembler does things. 😛 )
Now, with that, you’d need an assembler (like Yasm) to turn that code into an executable. (You’d need more code, though. What you have here, won’t run correctly as is. At the very least, you need a
retat the end so that the CPU doesn’t run off the rails.) You could conceivably use a compiler and embed everything in an__asmblock (or your compiler’s equivalent), but you generally wouldn’t do that if you’re writing in pure assembly language. That’s kinda like using a sledgehammer to pound in nails.