displaying msg via video memory

[b][red]This message was edited by shaolin007 at 2003-11-4 8:0:29[/red][/b][hr]
Can't seem to get my code to work quite the way I want it to. It prints out garbage, or whatever is in memory I guess. I'm using NASM and here is my code.

[code]

BITS 16 ;Set code generation to 16 bit mode
ORG 0x0100 ;Set code start address to 0100h

mov ax, 0b800h
mov es, ax
mov bx, hellomsg
call printstring


printstring:
mov ax, bx
cmp al, '0'
je done
mov [es:di], al
inc di
inc di
inc bx
jmp printstring

done:
mov ah, 08h
int 21h
mov ax, 4c00h
int 21h

hellomsg db "Hello There!0"

[/code]

Thanks for the help in advance.


Comments

  • : [b][red]This message was edited by shaolin007 at 2003-11-4 8:0:29[/red][/b][hr]
    : Can't seem to get my code to work quite the way I want it to. It prints out garbage, or whatever is in memory I guess. I'm using NASM and here is my code.
    :
    : [code]
    :
    : BITS 16 ;Set code generation to 16 bit mode
    : ORG 0x0100 ;Set code start address to 0100h
    :
    : mov ax, 0b800h
    : mov es, ax
    : [red][b]xor di, di ; You write at [ES:DI], so where is DI pointed?[/b][/red]
    : mov bx, hellomsg
    : call printstring
    :
    : printstring:
    : mov a[red][b]l[/b][/red], [red][b][[/b][/red]bx[red][b]][/b][/red]
    : cmp al, '0' [red][b]; What if you need to print "2003"?? - You will print only "2"![/b][/red]
    : je done
    :
    : mov [es:di], al
    : inc di
    : inc di
    : inc bx
    : jmp printstring
    :
    : done:
    : mov ah, 08h
    : int 21h
    : mov ax, 4c00h
    : int 21h
    :
    : hellomsg db "Hello There!0"
    :
    : [/code]
    :
    : Thanks for the help in advance.
    :
    :
    :

  • :It prints out garbage, HLP

    Your main problem was: no brackets around BX [BX] works
    like Asmguru62 pointed out.
    Below is some untested gibberish that might help a bit,
    and this could help too:
    http://bitdog.home.att.net/files/nasmenv.zip

    [code]
    BITS 16 ;Set code generation to 16 bit mode
    ORG 0x0100 ;Set code start address to 0100h
    JMP START ;jump over data & procedures

    ;up here labels are created before their accessed,
    ;which lowers the passes required by the assembler to find sizeof, short/near/far?

    ;hellomsg db "Hello There!0" ;zero=0 is ASCII where it's usually a value
    hellomsg db "Hello There!",0 ;notice the (",0) not (0")
    ; both work, but value is the correct way

    printstring:
    MOV AH,4 ;color 4 = red
    PSTR:
    ; mov al,bx ; you are moving the address of BX not the value at the addr
    ;and moving a word size into a byte size
    MOV AL,[BX] ; this is actually [DS:BX] indirection adr addressing

    ; cmp al,'0' ;ASCII check
    CMP AL,0 ; value check
    je done

    ; OR AL,AL ;check for 0=zero
    ; JZ done ;this is my prefered way

    mov WORD [es:di],AX ; write char & color to ES:DI destination
    ;Nasm requires size= WORD when indirection is the destination
    inc di
    inc di
    inc bx
    jmp SHORT PSTR ; it's within 128 bytes so JMP SHORT works
    done:
    RET ; return from caller straightens out your stack
    ;CALL PRINTSTRING pushes the return address on the stack
    ;and you didn't clear that PUSH with a POP by returning

    START:
    mov ax, 0b800h
    mov es, ax
    xor di, di ; [ES:DI] = 0xB800:0000 upper left corner of screen
    mov bx, hellomsg
    call printstring
    MOV AH,8 ;pause
    INT 21h
    MOV AX,0x4C00 ; exit program with errorlevel 0 in AL reg
    INT 21h
    [/code]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories