;These procedures demonstrate the difference between call by address and ; call by value. .model small .186 .stack 100h .data msgValIn db "The value of data before calling procedure value is $" msgValOut db "The value of data after calling procedure value is $" msgAddIn db "The value of data before calling procedure address is $" msgAddOut db "The value of data after calling procedure address is $" data dw ? .code include Asm_io.inc main proc mov ax,@data mov ds,ax call passByValue call passByAddress mov ax,4c00h int 21h main endp passByValue proc push ax mov data,3 push offset msgValIn ;print data before the call push data call writeValue add sp,4 push data ;pass by value call value add sp,2 push offset msgValOut ;print data after the call push data call writeValue add sp,4 pop ax ret passByValue endp value proc push bp mov bp,sp mov word ptr [bp+4],7 ;change the value on the stack mov sp,bp pop bp ret value endp passByAddress proc push ax mov data,3 push offset msgAddIn ;print data after the call push data call writeValue add sp,4 push offset data ;pass by address call address add sp,2 push offset msgAddOut ;print data after the call push data call writeValue add sp,4 pop ax ret passByAddress endp address proc push bp mov bp,sp push bx mov bx,[bp+4] ;get the address of data from the stack mov word ptr [bx],7 ;change the value of data in the data segment pop bx mov sp,bp pop bp ret address endp writeValue proc push bp mov bp,sp push dx push ax push [bp+6] call writeString mov ax,[bp+4] call print_signed call crlf pop ax pop dx mov sp,bp pop bp ret writeValue endp writeString proc push bp mov bp,sp push ax push dx mov dx,[bp+4] mov ah,09h int 21h pop dx pop ax mov sp,bp pop bp ret writeString endp crlf proc push ax push dx mov ah,02h mov dl,0dh int 21h mov dl,0ah int 21h pop ax pop dx ret crlf endp end main