我正在尋找一種方法來高效地計算我的程序中的數據和代碼段以進行分配。測量ASM中的數據和代碼段的大小
我環顧四周,發現this thread,但它似乎沒有得到我正在尋找的答案。根據我從masm獲得的清單,當從CS中減去DS(通過我的調試器讀取的值)時,我得到了2h,其中10將是20h,儘管實際代碼段是23h。
我發現找出代碼段的大小的一種方法是通過調用一小段代碼,在返回之前暫時將EIP放在堆棧上,從而使EIP進入程序的最後。
儘管這樣做有效,但它會在代碼段中添加大約10個字節,我將不得不適應在調用後發生的所有指令,特別是_end和add。如果可能的話,我希望獲得更高效的或至少是獲得代碼段大小的絕對方法。
至於數據段,我還沒有找到或有任何好的想法。在調試器中運行我的程序時,無論出於何種原因,我的DS和SS都是相同的。在這方面還是很新的,所以我不確定這是爲什麼。 我欣賞任何建議。
編輯添加的代碼(2014年10月1日)
INCLUDE Pcmac.inc
.MODEL SMALL
.586
.STACK 100h
.DATA
MsgX DB 'Please enter a name: ', '$'
MsgY DB 10,13,'You entered: ', '$'
BufferP DB 26 ;25 char + Return
StringSize DB 0
String DB 26 DUP (0) ;Buffer Space
.CODE
你好PROC
_Begin
_PutStr MsgX
_GetStr BufferP
lea bx, String ;load address of buffer into bx (Has to be an index or base register)
mov ax, 0 ;0 out ax
mov al, StringSize ;move the size of the string into al (can be any register)
add bx, ax ;add the size of string to it's address,
;we now have the address of the carriage ret (String + StringSize) in the bx register
mov ax, '$' ;move a character to ax (the character you wish to replace the carriage ret with)
mov [bx], ax ;mov ax or '$' to the location bx is pointing toward
_PutStr MsgY
_PutStr String
_Exit
你好ENDP
END Hello
沒有人說段不能重疊。要訪問下一個段中的第24個字節,相應的段寄存器必須爲2 – 2014-09-30 07:32:30
注意:2h x 10 = 14h。 2h x 10h = 20h。 – 2014-09-30 13:11:52