ZzToP
ZzToP

Reputation: 33

The program fails to proceed after a procedure in assembly 8086

Hi friends I can't go back after the "Upper" procedure to the next line I don't understand where ip has gone ...

.MODEL SMALL
.STACK  64
.DATA
input db 30,?,30 dup('$'),'$'
msg1 db "Please enter string to convert:", 0DH , '$'
msg2 db "Your converted input :", 0DH , '$'
TransFormsMan db 32 ; Going to use the dec value 32 to change my lowers chars..


.Code

Main proc
    mov ax, @data
    mov ds, ax
    ; Printing Message1 with a lineBreak
    lea dx, msg1
    mov ah, 09
    int 21H
    mov dl,0AH
    mov ah, 02
    int 21H
    call getString
    xor ax,ax
    lea ax,input
    mov cl,input + 1
    mov ch,0
    add ax,2
    push ax
    push cx
    ; Printing Message2 with a lineBreak
    lea dx, msg2
    mov ah, 09
    int 21H
    mov dl,0AH
    mov ah, 02
    int 21H
    call upper

    mov ah, 4ch
    mov al, 0
    int 21H
endp Main

print proc
    ;Handle bp 
    push bp
    mov bp,sp
    add bp,2
    ;pushes
    push ax
    push bx
    push dx
    ;body:
    mov dx,[bp+2]
    ;add dx,2 ; we want to print without the size of the string. 
    xor ax,ax
    mov ah,9
    int 21H
    xor ax,ax
    xor dx,dx
    mov dx,13 ; Getting down line in the output
    mov ah,2
    int 21h  
    mov dx,10
    mov ah,2
    int 21h ; ^^
    ;pops
    pop dx
    pop bx
    pop ax
    pop bp
    ret 2
endp print

getString proc
    ;Handle bp 
    push bp
    mov bp,sp
    add bp,2
    ;pushes
    push ax
    push dx
    ;body:
    mov ah,0AH
    lea dx,input
    int 21H
    xor ax,ax
    xor dx,dx
    mov dx,13 ; Getting down line in the output
    mov ah,2
    int 21h  
    mov dx,10
    mov ah,2
    int 21h ; ^^
    ;pops
    pop dx
    pop ax
    pop bp
    ret
endp getString

Upper proc
    ;Handle bp 
    push bp
    mov bp,sp
    add bp,2
    ;pushes
    push ax
    push bx
    push cx
    push dx
    push si
    push di
    ;body:
    mov bx,[bp+4]
    mov cx,[bp+2]
    sub sp,[bp+2]
    mov si,sp
    mov di,si

    loopy:
        xor ax,ax
        mov al,[bx]
        cmp al,'z'
        ja notLower
        cmp al,'a'
        jl notLower
        sub al, 32
        mov [si],al
        inc si
        inc bx
        loop loopy
    notLower:
        cmp cx,0
        je stackPrint ; if the last letter was lower so we need to get out of here...
        inc bx
        loop loopy
    stackPrint:
    mov byte ptr [si],'$'
    push di
    call print
    add sp,[bp+2]
    ;pops
    pop di

    pop di
    pop si
    pop dx
    pop cx
    pop bx
    pop ax
    pop bp
    ret 4
endp Upper

END Main

Like I said the code works well but every time after the "Upper" procedure ends I can't continue to the following lines because the ret does not return me to the line that comes after calling the procedure

Upvotes: 1

Views: 169

Answers (1)

Sep Roland
Sep Roland

Reputation: 39701

mov byte ptr [si],'$'
push di
call print
add sp,[bp+2]
;pops
pop di

In the Upper proc , the pop di is the culpritt. The print proc already returned with the parameter removed from the stack (ret 2).
Just delete pop di.

BEWARE

If the SS and DS segment registers are different in your program, numerous other changes are needed to make this "String In The Stack" solution work!

Upvotes: 3

Related Questions