News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Problem with tuts I'm taking

Started by Statix Star, January 06, 2005, 05:32:58 AM

Previous topic - Next topic

Statix Star

;This is a simple program which displays "Hello World!" on the

;screen.


.model small

.stack                 

.data           

     

Message db "Hello World!$"              ;message to be display


.code           

.mov dx,OFFSET Message           ;offset of Message is in DX

.mov ax,SEG Message              ;segment of Message is in AX

        mov ds,ax                       ;DS:DX points to string

        mov ah,9                        ;function 9 - display string                 

        int 21h                         ;call dos service                 


        mov ax,4c00h                    ;return to dos DOS

        int 21h     

.

END start                               ;end here


Hi I use the linker5.63 but I think there are some bugs in the debugger it won't let me compile, also I add the .dosseg and it won't let me compile it. I had tried with a86 and none, I haven't tried with tasm 2.0 tlink 3.0 LOL the ancient tasm.
This seems a great tutorial.

MichaelW

#1
Here is a reformatted version of the code you posted:

;This is a simple program which displays "Hello World!" on the
;screen.
.model small
.stack
.data
    Message db "Hello World!$"      ;message to be display
.code

    .mov dx,OFFSET Message      ;offset of Message is in DX

    .mov ax,SEG Message         ;segment of Message is in AX

    mov ds,ax                   ;DS:DX points to string

    mov ah,9                    ;function 9 - display string

    int 21h                     ;call dos service


    mov ax,4c00h                ;return to dos DOS

    int 21h

.

END start                       ;end here

Trying to assemble it with this batch file:

ML /Fl /Sa /c /Zi hello1.asm > asm.txt
LINK16 hello1.obj,,hello1.map;
pause

Returns these error messages in asm.txt:

Assembling: hello1.asm
hello1.asm(12) : error A2008: syntax error : mov
hello1.asm(14) : error A2008: syntax error : mov
hello1.asm(27) : error A2008: syntax error : .
hello1.asm(29) : error A2006: undefined symbol : start

In addition to fixing the four problems noted, you need to initialize DS with the segment address of the data segment. There are multiple methods of doing this, but the simplest would be to use a .STARTUP directive at the start of the code segment. This would initialize DS and fix the fourth problem by setting the starting address for the program to the address of the .STARTUP directive. Another method of initializing DS with the segment address of the data segment would be:

mov  ax, @data
mov  ds, ax

And another method of fixing the fourth problem would be to add a start: label at the start of the code segment.

Also, you can make the program wait for a key press before terminating by adding:

mov  ah,0
int  16h

before the call to function 4Ch. This will call the BIOS Read Character function, which will wait until a key is available before returning.

I guess I should have added that:

mov  ax, SEG Message
mov  ds, ax

Will set DS to the segment address of the data segment, but IMO it would be much better to do this as a standard operation at program startup, and that is why Microsoft provided the .STARTUP directive. There is also an .EXIT directive that can be used to terminate the program.


eschew obfuscation

pbrennick

The following cde works...

; This is a simple program which displays
; "Hello World!" on the screen.
        .model  small
        .stack
        .data
Message db      "Hello World!$"         ; message to be display

.code
start:  mov     dx, OFFSET Message      ; offset of Message is in DX
        mov     ax, SEG Message         ; segment of Message is in AX
        mov     ds, ax                  ; DS:DX points to string
        mov     ah, 9                   ; function 9 - display string
        int     21h                     ; call dos service
        mov     ax, 4c00h               ; return to dos DOS
        int     21h

        END     start


I  guess you are planning to use the small model defaults?  I think the suggestions from MichaelW are a better way to go.  That way you know exactly what is going on.

Paul

Statix Star

Hey thanks I had copied the information and pass it to my pc, I guess I understand.

Statix Star

pbrennick,

I just follow the tutorials from gavians at programmersheaven.com , I usually downloaded blackcat by Adam Hyde but it it was too annoy so, I just kept with the best one. I haven't deeply studied the tiny, huge, large, small, etc. Also the stack I seem mostly
it was from 100h; from other tuts.


.model small
.stack
.data

MessageBox db "Hello World!$"
.code             ;I had tried to put here instead .startup or .code .startup and it doesn't work.
                     ;I use .start: and it worked, I haven't tried any other but I want to know how?
.startup
mov dx, offset message  ;vortex's example from achilles I had recorded the code ds, @data ax,ds
mov ax, seg message

mov ds, ax
mov ah, 9

int 21h

                                 ;mov ah,0
                                 ;int 16h Correct?
mov ax,4c00h

int 21h

end start               
                ; .exit here?