Writing to Stack in Extern 8086 Procedure inactive via MOV [BP], AL

Problem:

Inactive write to the stack inside an external procedure

Code:

Inside an external procedure, which asks the user to enter a string, and then returns it to the main part via the stack.

The string is defined in the data segment with a name different from the name of the data segment inside the main procedure file.

Data_segment_name_ext segment para
ORG 10H
Str  DB 20,?,20 DUP (?)
Data_segment_name_ext ends

and segment segment declaration:

Stack_segment_name segment para stack
db 64 dup(0) ;define your stack segment
Stack_segment_name ends

Initially, at the beginning of the procedure, I declared it public and installed BP in Stack top:

PUBLIC MyProc
Code_segment_name segment
MyProc PROC FAR
assume SS:Stack_segment_name,CS:Code_segment_name,DS:Data_segment_name_ext
PUSH BP 
MOV BP,SP

The line is read by the function AH = 0x0A interrupt 0x21

LEA DX,Str
MOV AH,0Ah
INT 21H

Trying to save a string onto the stack using the following loop:

MOV CX,22 ; The string length
MOV SI,00 ; used as an index
TRA1:
DEC BP
MOV AL,Str[SI] ; Str is defined in the data segment
MOV [BP],AL 
INC SI
LOOP TRA1

Debugging the program using code 4.01 and MASM 6.11 leads to the following:

1- DS Str. [ , ]

2- :

SP = 0xBA BP = 0xA4 (.. 0xBA-0x16 ( )) SS: 0xA4 8 SS: SP .

str = 'ABCDEFGHIJ' 'GHIJ'

>DB SS:0xA4

SS:00A4 00 00 00 00 00 00 00 00   00 00 4A 49 48 47 E7 05  ..........JIHG.. 
SS:00B4 7E 00 FD 05 02 02 00 00   0A 00 0C 06 B8 E7 05 8E  ~...............

: 060C: 000A CS: IP extern @SP = 0xC0 ( SS: 0xBC, SS: 0xBD, SS: 0xBE, SS: 0xBF)

3- MOV [BP], AL MOV [BP], 33h : 33h 8 TOS

4- SS (.. MOV SS: [BP], AL) ,

, , ?

+4
2

MyProc - , , call. :

sub  sp, 22
call MyProc

DS , .

mov  ax, 20
sub  sp, ax
push ax         ;This sets up the correct buffer DOS expects
call MyProc
...
MyProc PROC FAR
assume SS:Stack_segment_name,CS:Code_segment_name
PUSH BP 
MOV  BP,SP
push ds
push ss
pop  ds
lea  dx, [bp+6]
;String is being read by function AH=0x0A interrupt 0x21
MOV AH,0Ah
INT 21H
pop  ds
...

, 64 . , .

+2

SP . . SP , , - (, ).

, SP (SUB SP, 22). , 22 .

. SP (ADD SP, 22). 22 .

, .

:

Stack

  • MyProc.
  • .
  • , .
  • .
  • : .
  • , MyProc.

4 , "ABC..HJ", MyProc. .

.

+2

Source: https://habr.com/ru/post/1619629/


All Articles