Declared
a look in the white population of a question, a very simple question about the compilation, and then let the analysis process, then answer a question out, and then I looked and found there are some I do not very know, so check the internet a lot of things, and then recorded
First, look at the title bar (Source: www.chegg.com/homework-help/questions-and-answers)
In order to facilitate reading, I've written comments on the
asm annotated link: https: //pan.baidu .com / s / 1svcIP9nUdYMDXkBsdI-ChQ
extraction code: jnie
; READING CODE - STACK
; ;list the output of the following program assuming the input is as follows:
; 101
; 232
; 48
; 17
include PCMAC.INC ;Add the PAMAC.INC to the source file ( call library)
NEWLINE EQU _PutCh 13, 10 ; Equivalent to '\n' newline
.MODEL SMALL
.STACK 100h ; The first address of the stack
.DATA ; Data segment
Message1 DB 'Total sold today, $' ; Message1 for the convenience of the following calls
Message2 DB ' , is: $' ; Message2
.CODE ; Code segment Indicates the beginning of the code segment
EXTERN GetDec: NEAR, PutDec:NEAR ; Declare a function GetDec -> input PutDec -> output
Main PROC ;begin
mov ax, @data
mov ds, ax
_GetDate ;time
push cx ;
push dx
push dx
call SubInput ;send control to subprocedure
mov bx, ax
_PutStr Message1 ;output 'Total sold today,'
pop dx ;pop dx
mov al, dh
mov ah, 0 ;just assign dh to ax (numerical value)
call PutDec ;output dh
_PutCh '/' ;output '/'
pop dx
mov al, dl
mov ah, 0
call PutDec
_PutCh '/' ;the same as above
pop cx
mov ax, cx
call PutDec
_PutStr Message2 ;output ' , is:' here! 'Total sold today, 11/26/2019 , is:'
mov ax, bx
call PutDec ;'Total sold today, 11/26/2019 , is: 398'
NEWLINE ; newline
mov al, 0 ; Return code of 0
mov ah, 4ch ; Exit back to MSDOS
int 21h
Main ENDP
.Data ; re-enter the data segment for this procedure
MessageSub DB 'Enter a number $'
Mystery DW ?
.CODE ; return to coding
SubInput PROC
mov cx, 4 ;Read four values in a loop
myLoop:
_PutStr MessageSub
call GetDec
add Mystery, ax ; sum++
dec cx
jnz myLoop
mov ax, Mystery
ret
SubInput ENDP
END Main ; Tells where to start execution
Then let answer a few questions:
1- What is the purpose of line 8?
Add the PAMAC.INC to the source file ( call library)
2- Why do we include line 18?
Indicates the beginning of the code segment
3- What can we replace lines 21 and 22 with?
mov bx , @data mov ds , bx
4- What registers does _GetDate use? (Hint: find it in the book)
*cx , dx , ss
5- What register is at the top of the stack right after line 26?
dx
6- Why are we pushing dx twice?
Lines 31 and 36 use the dx ,so we should have two dx to pop
7- What register is at the top of the stack right after line 35?
cx
8- Suppose the offset of line 61 is 00000080 and the offset of line 28 is 00000040, after the call instruction in line 27 what offset is ESP holding? What about EIP?
ESP: 00000036 EIP: 00000080
9- After the execution of line 69 what happens to the offsets in ESP and EIP?
ESP+=4 pop EIP and point to line 28
10- What is the purpose of lines 36 and 37?
Assign dl to ax (numerical value)
11-How does the assembler know where the start of the program is?
The assembler finds the Main PROC to determine the start of the program
Here I have written down the answers to the problem, then we combine to take a look at the answer, what are the knowledge pair of points!
First the first question, include what purpose?
We all know that at the time of writing, the need to add a variety of include, that is it for this purpose in the front? include a macro is designed to head a library file or introduced to the source file, that is, I use it;
The second question, .code
.data .code this is represents the beginning of a data segment, code segment, then for those mian proc, then there will begin to have an end, it is necessary to mark an end of the end;
Third question, @ data or data
@data is the first address of the data segment, you want to put that ds is in the data segment, you will need to register as a broker; do not allow directly @data (immediate) to the ds
Fourth asked, GetDate
Wow, this is what Ghosts, I have not found on Baidu, ooo, ooo, but I guess it is to obtain the system time, then the question again, save where acquisition time, and after analysis, I feel is saved in the cx dx inside, and there was in cx, dx which is dated May, so time is behind the month / day / year US standards this is written;
Five hundred sixty-seven slightly
The eighth question, the impact of the call instruction for esp, eip of
We all know, for a good program, it needs a reasonable routine to assist, so looking at the code concise, so in the compilation, there is a call statement, then what is this principle call it? What pushed the order again? After we have a function as a subroutine, you know, call is a call function that can be custom libraries can be defined, then some function with parameters, then this time we need to put parameters from right to left hand pushed onto the stack (from right to left pushed onto the stack, pop up, it is the left to right), then the compiler will automatically eip pushed onto the stack, then changes need eip Jump address, in short, call time, esp will be -4, because pressed into eip, and ret time, will + 4, pop the eip;
Ninety eleven slightly
Seen in the title
EXTERN is a definition, a statement
_GetDate acquisition system time
_PutStr output string
_PutCh output a single character
mov Al, 0; the Return code of 0
mov AH, 4ch; Exit the Back to MSDOS
int 21H interrupt and then quit
EQU assignment, or named
_PutCh 13 , 10? ? Wrap? Not found