# Assembly Language and Linux



## InterKnight (Oct 19, 2004)

Hello, everyone. Long time no see. 

Well, last year I switched over to Linux. Now I am in an Assembly Language Programming course at college--this is where my problem begins.

I have a lab exercise which involves typing out a small ASM program from a typed hard copy. I have it typed out exactly as shown, but none of the assemblers on Linux (nasm, yasm, gas) are assembling--they all come up with errors.

This class focuses on programs for IA-32 family processors.

Is there something I need to do, ro is there a different assembler I would need to use? The book recommends the Microsoft Macro Assembler (MASM), and our professor recommended Borland Turbo Assembler (TASM). Neither the book nor the professor, however, had any present knowledge to recommend a Linux-based assembler.

Does anyone have a clue as to what I should do regarding this situation? Worst case scenario, I could try to run the Borland Turbo Assembler in Wine or a virtual machine to see if it would work.

Thanks for any and all help, everyone.

Please take care.


----------



## InterKnight (Oct 19, 2004)

Hello, again.

I found a slight workaround for this, but for anyone to do it, around 512MB-1GB of RAM would be necessary--and fortunately, I upgraded my RAM to 1GB last year.

Let me explain what happened: NASM (Netwide Assembler) for Linux does not support certain directives which are used in TASM (Turbo Assembler), such as *.MODEL*. The assembler works, but things have to be done a different way, and I do not have the knowledge to accomplish this at this time as I have no ASM programming experience.

My solution for this problem is this: I installed a Windows XP virtual machine under VirtualBox, setup TASM in the VM, and now use this method for doing the Assembly Language Programming course assignments. (This is why I mentioned the RAM necessity above)

In any case, it works.

Thanks, everyone.

Take care.


----------



## tomdkat (May 6, 2006)

What kind of errors were you getting from the GNU assembler (gas)?

Peace...


----------



## InterKnight (Oct 19, 2004)

Hello, tomdkat.

Thanks for the response.

Here si the code for the program:

```
; AUTHOR:	RKC
; CLASS:	CS241
; DUE DATE:	January 23, 2008
; DESCRIPTION:	This is a simple program which will demonstrate the creation, assembling, linking, and execution of a basic
;		assembly language program.
.MODEL	SMALL
.STACK	100h

.DATA
	TimePrompt DB 'Is it after 12 noon?(Y/N)?$'
	GoodMorningMessage  LABEL  BYTE
	  DB  13,10,'Good morning, world!',13,10,'$'
	GoodAfternoonMessage  LABEL  BYTE
	  DB  13,10,'Good afternoon, world!',13,10,'$'
	
.CODE
	mov ax,@data
	mov ds,ax				;set DS to point to the data segment
	
	mov dx,OFFSET TimePrompt		;point to the time prompt
	mov ah,9				;DOS print string function #
	int 21h					;display the time prompt

	mov ah,1				;DOS get character function #
	int 21h					;get a single-character response

	cmp al,'y'				;typed lowercase y for afternoon?
	jz IsAfternoon				;yes, it's after noon

	cmp al,'Y'				;typed uppercase Y for afternoon?
	jnz IsMorning				;no, it's before noon

	IsAfternoon:
	  mov dx,OFFSET GoodAfternoonMessage	;point to the afternoon greeting
	  jmp DisplayGreeting

	IsMorning:
	  mov dx,OFFSET GoodMorningMessage	;point to the before noon greeting

	DisplayGreeting:
	  mov ah,9				;DOS print string function #
	  int 21h				;display the appropriate greeting

	mov ah,4ch				;DOS terminate program function #
	int 21h					;terminate the program

END						;this line is a must in every assembly language program
```
Here are the errors which I receive from gas:

```
Lab1.asm: Assembler messages:
Lab1.asm:1: Error: no such instruction: `RKC'
Lab1.asm:2: Error: no such instruction: `cs241'
Lab1.asm:3: Error: no such instruction: `due DATE:January 23,2008'
Lab1.asm:4: Error: no such instruction: `this is a simple program which will demonstrate the creation,assembling,linking,and execution of a basic'
Lab1.asm:5: Error: no such instruction: `assembly language program.'
Lab1.asm:6: Error: unknown pseudo-op: `.model'
Lab1.asm:7: Error: unknown pseudo-op: `.stack'
Lab1.asm:10: Error: no such instruction: `timeprompt DB 73s it after 12 noon?(Y/N)?$10GoodMorningMessage LABEL BYTE'
Lab1.asm:11: Error: no such instruction: `db 13,10,71ood morning,world!4413,10,36'
Lab1.asm:12: Error: no such instruction: `goodafternoonmessage LABEL BYTE'
Lab1.asm:13: Error: no such instruction: `db 13,10,71ood afternoon,world!4413,10,36'
Lab1.asm:15: Error: unknown pseudo-op: `.code'
Lab1.asm:16: Error: invalid char '@' beginning operand 2 `@data'
Lab1.asm:17: Error: too many memory references for `mov'
Lab1.asm:17: Error: no such instruction: `set DS to point to the data segment'
Lab1.asm:19: Error: too many memory references for `mov'
Lab1.asm:19: Error: no such instruction: `point to the time prompt'
Lab1.asm:20: Error: too many memory references for `mov'
Lab1.asm:20: Error: no such instruction: `dos print string function'
Lab1.asm:21: Error: junk `h' after expression
Lab1.asm:21: Error: suffix or operands invalid for `int'
Lab1.asm:21: Error: no such instruction: `display the time prompt'
Lab1.asm:23: Error: too many memory references for `mov'
Lab1.asm:23: Error: no such instruction: `dos get character function'
Lab1.asm:24: Error: junk `h' after expression
Lab1.asm:24: Error: suffix or operands invalid for `int'
Lab1.asm:24: Error: no such instruction: `get a single-character response'
Lab1.asm:26: Error: too many memory references for `cmp'
Lab1.asm:26: Error: no such instruction: `typed lowercase y for afternoon?'
Lab1.asm:27: Error: no such instruction: `yes, it115after noon'
Lab1.asm:29: Error: too many memory references for `cmp'
Lab1.asm:29: Error: no such instruction: `typed uppercase Y for afternoon?'
Lab1.asm:30: Error: no such instruction: `no, it115before noon'
Lab1.asm:33: Error: too many memory references for `mov'
Lab1.asm:33: Error: no such instruction: `point to the afternoon greeting'
Lab1.asm:37: Error: too many memory references for `mov'
Lab1.asm:37: Error: no such instruction: `point to the before noon greeting'
Lab1.asm:40: Error: too many memory references for `mov'
Lab1.asm:40: Error: no such instruction: `dos print string function'
Lab1.asm:41: Error: junk `h' after expression
Lab1.asm:41: Error: suffix or operands invalid for `int'
Lab1.asm:41: Error: no such instruction: `display the appropriate greeting'
Lab1.asm:43: Error: too many memory references for `mov'
Lab1.asm:43: Error: no such instruction: `dos terminate program function'
Lab1.asm:44: Error: junk `h' after expression
Lab1.asm:44: Error: suffix or operands invalid for `int'
Lab1.asm:44: Error: no such instruction: `terminate the program'
Lab1.asm:46: Error: no such instruction: `end'
Lab1.asm:46: Error: no such instruction: `this line is a must in every assembly language program'
```
I used Gedit to write the rpogram. Should I use something else? I see it's not recognizing comments (.

Thanks again.

Take care.


----------



## tomdkat (May 6, 2006)

Naw, I doubt it's the editor you're using. Which version of gas are you running? Use the "gas --version" command to find out.

Peace...


----------



## InterKnight (Oct 19, 2004)

Here is what I get for the version. Hope this helps.


```
GNU assembler (GNU Binutils for Ubuntu) 2.18
Copyright 2007 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `i486-linux-gnu'.
```
Thanks again.


----------



## tomdkat (May 6, 2006)

Additionally, it looks like gas supports *different* comment characters on different platforms.

I presume you're using a 32-bit (i386) Linux system. Check out the gas manual on comments for your platform. 

Peace...


----------



## InterKnight (Oct 19, 2004)

Thanks.

I changed the comment format in the file, but GAS also (like NASM) seems to not recognize the *.model* and the *.stack* directives. I'm not sure how to work around this, but worse comes to worse I can just use the virtualization method.


----------



## tomdkat (May 6, 2006)

Looks like .model and .stack are MASM-specific directives that TASM supports to be compatible with MASM. I think .stack might be implementable in GNU as using a ".section" directive. I would post a message on the GNU as mailing list to find out how to better deal with MASM specific directives.

Here is another link that might be helpful.

Peace...


----------



## ZeRealBigBoss (Mar 17, 2007)

NASM under Linux does not recognise the .model directive because it always runs in flat mode. You get rid of the 64k barrier for free. If you used MASM, you will have to re-think in many details. Indeed, TASM is a very good one, but before you have that one set up correctly on a certain machine, we are a few weeks and much trial-and-error onwards.

Many assembler compilers recognise the // or /*......*/ instead of the ;

Have a look here:

http://nasm.sourceforge.net/
http://nasm.sourceforge.net/doc/nasmdoc1.html
http://www.ibm.com/developerworks/linux/library/l-gas-nasm.html


----------

