TAILIEUCHUNG - The 80x86 IBM PC and Compatible Computers- P6

The 80x86 IBM PC and Compatible Computers- P6: Praised by experts for its clarity and topical breadth, this visually appealing, one-stop source on PCs uses an easy-to-understand, step-by-step approach to teaching the fundamentals of 80x86 assembly language programming and PC architecture. Offering users a fun, hands-on learning experience, it uses the Debug utility to show what action the instruction performs, then provides a sample program to show its application. | In Table 7-1 the register indicates the register used for the return value. If the value returned is a pointer address AX will hold IP if it is NEAR and DX AX will hold CS IP if it is FAR. This is illustrated in Example 7-9 where the sum of x y and z is returned to C through DX and AX as expected by C. DX has the higher word and AX the lower word. In the stack frame illustration first notice that since the procedure is FAR both CS and IP are saved on the stack. Therefore to access the C arguments it is necessary to use BP 6 BP 8 and BP 10 displacements. As a rule if the Assembly procedure is NEAR the last argument passed by C is accessed by the displacement of BP 4 and if it is FAR it is accessed by BP 6 displacement. In order not to be bothered by these rules new assemblers have become more user friendly as shown in the next topic. Example 7-9_ Three values of int size are passed by a C function to an Assembly procedure. The assembly code adds them together and returns the total sum back to C which displays the result. extern unsigned long sum int int int main printff The sum is equal to u sum 500 6500 200 The following is .MODEL MEDIUM .CODE PUBLIC SUM this far procedure gets three words from the stack and adds them together. At the end DX AX has the total sum SUM PROC FAR PUSH BP save BP MOV BP SP use it as SP SUB AX AX clear AX MOV DX AX and DX ADD AX BP 6 add the first ADC DX 0 add the carry ADD AX BP 8 add the second ADC DX 0 add the carry ADD AX BP 10 add the third ADC DX 0 add the carry POP BP restore BP RET go back to C SUM ENDP END New assemblers and linking withC In recent years some Assemblers have made linking with C much easier. Using MASM or TASM and higher ends the need to worry about the displacement or about beginning the names common to C and Assembly with an underscore or about saving BP. The program in Example 7-9 is rewritten on the following page. Notice .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.