0
ideal
model small
stack 1024
dataseg
    array1 db 11 dup(?)
codeseg
org 100h
PROC MAIN
    CALL GETINPUT
    CALL PRINTARRAY
EXIT:
    mov ah, 4ch
    int 21h
ENDP

PROC PRINTARRAY
    lea dx, [array1]
    mov ah, 9
    int 21h
    ret
ENDP

PROC GETINPUT
    mov bx, offset array1
    GET:
        CALL GETCHAR
        cmp al, '.'
        je ENDGET
        mov [array1+bx], al
        inc bx
        cmp bx, 10
        jge ENDGET
        CALL PRINTSPACE
        jmp GET
    ENDGET:
    mov [array1+bx], '$'
    ret
ENDP

PROC GETCHAR
    mov ah, 1
    int 21h
    ret
ENDP

PROC PRINTSPACE
    mov dl, ' '
    mov ah, 2
    int 21h
    ret
ENDP

PROC PRINTCHAR
    mov ah, 2
    int 21h
    ret
ENDP

END MAIN

Im getting an NTVDM error cs:0423 ip:0125 when adding '$'. without the sentinel i can't print the array without garbage and other characters in it. :( i dont know if its because of my OS, windows 7 32bit, or assembler. please help me. :(

bheek
  • 11
  • 3
  • 1
    Your loop appears to allow up to 10 chars to be stored in `array1` (your exit condition is `al=='.' || bx >= 10`. So you might end up writing the '$' to `[array1+10]` (i.e. the 11th byte), which is out of bounds since you've declared array1 as an array of 10 bytes. – Michael Mar 06 '13 at 14:38
  • You're right. Changed it to 20. Still the same error. – bheek Mar 06 '13 at 15:23

1 Answers1

1

Look at these two instructions:

mov bx, offset array1
GET:
    ...
    mov [array1+bx], al

Doesn't it look odd to you that you take the address of array1 and then add it to itself in array1+bx?

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180