7

I'm currently in an assembly course and i have to run the code on Mac OS X and I'm lost on how i should run the code on Mac OS X

Here's the code:

; Description: This program adds and subtracts 16‐bit integers.
; Revision Date:
INCLUDE Irvine32.inc
.code
main PROC
mov ax, 650          ; AX = 650h
sub ax, 50h          ; AX = 600h
sub ax, 100h         ; AX = 500h
sub ax, 300h         ; AX = 200h
call DumpRegs        ; display registers
exit
main ENDP
END main

This is the error message that i am receiving

Tayvions-MacBook-Pro:~ tayvionpayton$ cd Documents/Code/
Tayvions-MacBook-Pro:Code tayvionpayton$ nasm -f macho32 -o0 assembly_Tp.asm 
assembly_Tp.asm:4: error: parser: instruction expected
assembly_Tp.asm:5: warning: label alone on a line without a colon might be in error
assembly_Tp.asm:6: error: parser: instruction expected
assembly_Tp.asm:12: warning: label alone on a line without a colon might be in error
assembly_Tp.asm:13: error: symbol `main' redefined
assembly_Tp.asm:13: error: parser: instruction expected
assembly_Tp.asm:14: error: parser: instruction expected
Tayvions-MacBook-Pro:Code tayvionpayton$ 
1
  • 2
    Your code is specifically written with MASM syntax and this code was likely intended for use on Windows. If you are taking a course and the target is Windows then you will need to install Windows in a virtual machine (VirtualBox, Parallels etc) on OS/X and then you set up a development environment inside that virtual machine. Otherwise you will need to create code specific for OS/X. Commented Mar 6, 2017 at 14:34

1 Answer 1

4

Assembler Code is not run, it is:

  1. Assembled/Compiled - There are a few choices depending on style and syntax. In that you've used Intel syntax try NASM. There is also gnu assembler which is used when writing source code in what is called AT&T Syntax syntax. See GAS.
  2. Once you compile the source code to an object code format, a linker is invoked to resolve external references and/or attaching static libraries to create an executable file. You do this with gnu linker [LD].3

Here are examples of a two step compile/link using NASM:

First compile the source code to an object file. This example is 32 bit:

nasm -f macho32 -O0 helloworld.asm 

This will produce a helloworld.o (object) file. You then need to finish this by linking:

ld helloworld.o -o helloworld

You can now run with ./helloworld

Sign up to request clarification or add additional context in comments.

4 Comments

OS X does have an assembler, it's called as. However, you probably have to install Xcode to get it and it uses AT&T syntax.
If you pay attention to the question, the OP already HAS NASM. The OP's problems stems from trying to compile the Windows32 MASM source with NASM, which will not work at all. Actually the NASM has some TASM compatibility switch, so simpler source may be compiled with few changes, but the resulting linux binary would just crash, as it would try to call non existent windows services. It would be maybe possible to cross-compile in Mac to produce windows executable, but the OP would still need windows (or wine) to run it, so he can as well install the free core Win SDK + with MASM.
Now I see the OP did add error messages from NASM later, so maybe you did answer the original question without that... then I sound too harsh with this comment, sry. :)
@Ped7g - Yes, I answered between the original and the edit. No hint he was using NASM unless I inferred that from the syntax but that would be ambiguous with other Intel-style OS X assemblers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.