please help me with my code.. :(
i am suppose to enter a 4-digit number and compare it to '0000'. i don't know why my code isn't working. i am not very good in debugging.. please help me

sseg segment para stack "stack"
	db 4096 dup(?)
sseg ends
dseg segment para public "data"
	msg db "Enter number: $"
	nline db 13, 10, "$"
	smaxlen db 50
	scurrlen db ?
	sdata db 50 dup(?) 
	number db "0000$"
	equal db "Equal!$"
	nequal db "Not equal!$"
dseg ends
cseg segment para public "code"
	assume cs:cseg, ds:dseg
compare proc 
        mov ax, cs
        mov ds, ax
        mov es, ax 
        cld  
        lea si, number
        lea di, sdata
        mov cx, 4
        repe cmpsb
        jnz not_equal
        mov dx, offset equal
        mov ah, 09h
        int 21h
        jmp exit_here
not_equal:
        mov dx, offset nequal
        mov ah, 09h
        int 21h
exit_here:
		ret
compare endp
main proc
	mov ax, dseg
	mov ds, ax
	mov ah, 09h
	mov dx, offset msg
	int 21h
	mov ah, 0ah
	mov dx, offset smaxlen
	int 21h
	mov dx, offset nline
    mov ah, 09h
    int 21h
	   
    call compare   
    
exit:  	
	mov ah, 4ch
	int 21h
main endp
cseg ends
end main

Can you tell us exactly how it is misbehaving?

On a side note: while not directly connected to the problem at hand, I would recommend setting up equates for the DOS calls, as that will make the code a lot easier to read and correct:

DOSCALL       EQU   21h
PRINTSTRING   EQU   09h
READSTRING    EQU   0Ah

... and so on.

I think I have the main showstopper problem worked out: while you set the DS segment prefix, you never set the SS segment prefix. Since the interrupts require a valid stack in order to work properly, the program crashed if this isn't set.

DOSCALL       EQU   21h
PRINTSTRING   EQU   09h
READSTRING    EQU   0Ah
EXIT_PROGRAM  EQU   4Ch

sseg segment para stack "stack"
    db 4096 dup(?)
sseg ends

dseg segment para public "data"
    msg db "Enter number: $"
    nline db 13, 10, "$"
    smaxlen db 50
    scurrlen db ?
    sdata db 50 dup(?) 
    number db "0000$"
    equal db "Equal!$"
    nequal db "Not equal!$"
dseg ends

cseg segment para public "code"
    assume cs:cseg, ds:dseg, ss:sseg

compare proc  
        cld  
        lea si, number
        lea di, sdata
        mov cx, 4
        repe cmpsb
        jnz not_equal
        mov dx, [offset equal]
        mov ah, PRINTSTRING
        int DOSCALL
        jmp exit_here
not_equal:
        mov dx, [offset nequal]
        mov ah, PRINTSTRING 
        int DOSCALL
exit_here:
        ret
compare endp

main proc
    mov ax, seg dseg
    mov ds, ax
    mov ax, seg sseg
    mov ss, ax
    
    
    mov ah, PRINTSTRING 
    mov dx, [offset msg]
    int DOSCALL
    mov ah, READSTRING
    mov dx, [offset smaxlen]
    int DOSCALL
    mov dx, [offset nline]
    mov ah, PRINTSTRING 
    int DOSCALL
       
    call compare   
    
exit:      
    mov ah, EXIT_PROGRAM
    int DOSCALL
main endp

cseg ends
end main

The comparison fails but at least it runs now.

thanks! i think i've worked it out now! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.