user379888
user379888

Reputation:

Basic Assembly Program

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

Upvotes: 2

Views: 1836

Answers (2)

cHao
cHao

Reputation: 86574

This is not quite valid 8086 assembly language. At least, it's not in any assembly syntax that i'm aware of.

  • For one thing, 8086 registers' names have two letters (they're named AX, BX, CX, DX, BP, SP, SI, and DI..plus some semi-special "segment registers" that can't be used for math).
  • If that A is 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

neg ax
add ax, 5

Or, for memory:

neg  word [A]
add  word [A], 5

... other stuff here ...
A: resw 1             ; some assemblers say this; others say `dw ?`

(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. :P )

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 ret at the end so that the CPU doesn't run off the rails.) You could conceivably use a compiler and embed everything in an __asm block (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.

Upvotes: 2

MarioDS
MarioDS

Reputation: 13073

It doesn't seem like the site you provided can run this code, as it sets a specific language. Assembly is not a language but a series of processor instructions. Download a 8086 emulator to run it.

Upvotes: 2

Related Questions