PDA

Click to See Complete Forum and Search --> : NASM and a piece of sample code for those learning


parksie
Aug 27th, 2000, 04:15 PM
Having started to learn asm this morning, I have now created my first application, and I am posting it here so that others can have a slight head start.

This is for the Netwide Assembler (NASM), a free assembler that produces object code for all x86 platforms. I used NASM, and VAL, an experimental linker.

NASM - http://www.web-sites.co.uk/nasm
VAL (requires LHA to unpack) - ftp://x2ftp.oulu.fi/pub/msdos/programming/lang/00index.txt

I made this using the free syntax-coloured editor NasmEdit, free from http://www.inglenook.co.uk/nasmedit/nasmedit.zip


; Title: Looped Hello World
;=================================================================================================== =======;
segment code ; Begin code segment

..start: mov ax, data ; Put address of data segment into DS
mov ds, ax ; No data path from memory to DS, so AX used as temporary storage
mov ax, stack ; Stack onto SS
mov ss, ax
mov sp, stacktop ; Top of stack onto SP (stack pointer)

mov cl, 0x31 ; Initialise CL to '1'

startpt: mov dx, hello ; Put address of hello into DX
mov ah, 0x9 ; Set AH to 9 (Output string)
int 0x21 ; DOS Interrupt 21

mov ah, 0x2 ; Set AH to 2 (Output character)
mov dl, cl ; Copy CL to DL
int 0x21 ; DOS Interrupt 21

mov dx, crlf ; Put address of crlf into DX
mov ah, 0x9 ; Set AH to 9 (Output string)
int 0x21 ; DOS Interrupt 21

add cl, 0x1 ; Add 1 to CL
cmp cl, 0x36 ; Compare CL to '5'
je end ; If equal, jump to end
jmp startpt ; Jump back to start

end: mov ax, 0x4c00 ; Set AX to 4c00 (Exit)
int 0x21 ; DOS Interrupt 21
;=================================================================================================== =======;
segment data ; Begin data segment

hello: db 'Hello World from Mike! This is time: ', '$' ; All DOS strings end in a $ sign.
crlf db 13, 10, '$'
;=================================================================================================== =======;
segment stack stack ; Begin stack segment
resb 32 ; Reserve 32 bytes on the stack
stacktop: ; Set top of stack

It was originally in hello.asm

I hope this is of help to anyone.

V(ery) Basic
Oct 22nd, 2000, 12:18 PM
I know it probably worked for everybody else, but it's one of those weeks for me: nothing works. I get:

segment name 'code' not recognised
segment name 'data' not recognised
segment name 'stack' not recognised

AND

I changed ..start to .start, and it doesn't complain about ..start any more.

Help would be most appreciated.

Thanks,

Moi.

Oct 22nd, 2000, 01:22 PM
What are you using to compile?

V(ery) Basic
Oct 25th, 2000, 01:05 PM
PLEASE? I haven't compiled/made a Single ASM program because none of the compilers WORK (NASM, TASM3.1 Shareware version, MASM32 etc.)

There's gotta be something wrong.

schnarf283
Oct 29th, 2000, 05:24 PM
Someone might get mad at me for this, but DOS debug does work.

Nov 5th, 2000, 06:03 AM
what is object code? is that the same as lowest-level machine code or it is higher, like pseudo code?