Results 1 to 6 of 6

Thread: NASM and a piece of sample code for those learning

  1. #1

    Thread Starter
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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/progra...ng/00index.txt

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

    Code:
    ; 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.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  2. #2
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    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.
    Courgettes.

  3. #3
    Guest
    What are you using to compile?

  4. #4
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    I'm not doing this for the Post Count ...

    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.
    Courgettes.

  5. #5
    Member
    Join Date
    Oct 2000
    Posts
    33

    Talking

    Someone might get mad at me for this, but DOS debug does work.

  6. #6
    Guest
    what is object code? is that the same as lowest-level machine code or it is higher, like pseudo code?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width