I'm really confused as to how stack pointers and byte pointers work. Here is the segment of code the problem is referencing:
.data
v1 db 'AB'
v2 db 'CD'
v3 db 'EF
.code
start:
mov ax,@data
mov ds,ax
mov sp,0100h
;call the subroutine
mov ax,offset v1
push ax
mov ax,offset v2
push ax
call subr
retsub:
The subroutine is:
subr:
push bp
mov bp,sp
mov si,[bp+6]
add si,1
mov dl,[si]
mov ah,2
int 21h
pop bp
ret
The three review questions associated with this problem have these answers:
1. After mov bp,sp in the subroutine, the value of the hex value in bp is 00F8.
2. The subroutine writes a single ASCII character to the standard output. It writes B.
3. The hex value in the sp register after the subroutine returns to the main program at the instruction at the label retsub is 00FC.
Can anyone walk me through the steps so that I can understand this process a little better?
The offset data table that I have is:
offset 00 01 02 03 04 05
data 41 42 43 44 45 46
The way that I approach this problem in my head is:
mov sp,0100h ;sp = 0100
mov ax,offset v1 ;ax = 4142
push ax ;4142 is pushed onto the stack
mov ax,offset v2 ;ax = 4344
push ax ;4344 is pushed onto the stack
call subr
stack
------
|4344|
------
|4142|
------
This is as far as I understand and I'm sure I'm not even doing this part right. If you can, please break it down with what bp and sp is with each step so that I can follow along and hopefully apply this to another review problem.
SSorSPexplicitly at the beginning of .COM and .EXE programs. DOS takes care of loadingSS:SP. Further, the stack size should be set with the appropriate stack segment definition or special keyword (if there's any supported by the assembler). ESP should not be loaded with an arbitrary hard-coded value, there must be space reserved for he stack.