CS344-321 Assembly Language Programming - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

CS344-321 Assembly Language Programming

Description:

CS344-321 Assembly Language Programming Period 32 – PowerPoint PPT presentation

Number of Views:128
Avg rating:3.0/5.0
Slides: 16
Provided by: Craz159
Category:

less

Transcript and Presenter's Notes

Title: CS344-321 Assembly Language Programming


1
CS344-321 Assembly Language Programming
  • Period 32

2
PARAMETER
PASSING ?????????????? ??????????????????????????
??? ?????????????????????????? ??????????
??????????? ?????????? ?????????????????????????
????? ????????????? ??????????????
???????????????? ?????????????????????????????????
??????????????????????? ?????????????????????????
??????????????????????? ??????????????????????????
???????????????????????? ??????????????????
(?????????????????????????????? BIOS ???? DOS
???? atoi ???? itoa) ?????????????????????????
????????????????????????????? ?????????????????
(activation record ???? stack frame) ??????
3
parameter 1
stack parameter 2
????????????????? bp 6 parameter n -1 bp
4 parameter n bp 2 return
address bp dynamic link bp - 2 local variable
1 bp - 4 local variable 2
???????????????????? local variable
n
???? near call
4
parameter 1
stack parameter 2
????????????????? bp 8 parameter n -1 bp
6 parameter n bp 2 return
address bp dynamic link bp - 2 local variable
1 bp - 4 local variable 2
???????????????????? local variable
n
???? far call
5
???????????????????????????
- ???????????????? ????????????????????????????
? (?????????????????????????????????????????)
?????????????????????????????????
?????????????????????? ?????????????????
????????????????????? ????????????????
??????????? - ???????????????????????????????????
???????? ????????????? 8086/8088 ???????? call
?????????????????????? ?????? call ??????????????
(return address ???????????????????????????
call) ?????????????????????????
??????????????????????????????????????????????????
????? (???????????????????????????? call ??????
???????????????????????????????????
????????????????????????? ???????????????????
??????????????????????????????????????????????????
???)
6
???????? ???? Pascal procedure
subr(para1integer, var para2integer, ,
paraninteger) ???????????? subr(para1,
para2, , paran) ????????????? mov ax,para1
call by value push ax
lea ax,para2 call by reference
push ax mov ax,paran
call by value push ax
call subr
7
???????? ???? C ??????????????????????? value
???????? subr(int para1, int para2,
, int paran) ???????????? subr(para1,
para2, , paran) ????????????? mov ax,paran
push ax ... mov ax,para2
push ax mov ax,para1
push ax call subr
8
??????????? ???????????????? ??????????? -
????????????? (dynamic link) ?????????????????????
???? - ???????????????????????????????????????????
??????????? ????????????????????????????
8086/8088 ??? ?????? subr proc near push bp
dynamic link mov bp,sp sub sp,_total_local_sizes
????? total_parm_sizes ????????????????
???????????????????????????????????????????
9
?????????????????????????? ??????????????????????
? ?????????????????? ? ???????????????
???????? mov sp,bp pop bp ret total_parm_sizes
subr endp ????? total_parm_sizes
???????????????? ?????????????????????????????????
??????????
10
???????? ???????????????????? ???????? program
final(input,output) var i,jinteger
procedure swap(var x,yinteger) var t
integer begin tx xy yt
end begin swap(i,j) end. ??????????????
????????????? 8086/8088 ?????????????????????????
Pascal ??????? ??????????????????????????????????
?? ????????????????? Pascal
11
dosseg .model small .stack 128 .data define
global variables here i dw ? j dw ?
12
.code swap proc near x equ bp6 parameter
x y equ bp4 parameter y t equ bp-2 local
variable t push bp save old bp as dynamic
link mov bp,sp set bp point to stack
frame sub sp,2 allocate space for t push bx
save content of bx mov bx,x t x be careful
x keeps address of i not value of i
mov ax,bx keep value of x in ax mov t,ax
then copy to t mov bx,y xy be careful x and
y keep address of i and j mov ax,bx keep
value of y in ax mov bx,x mov bx,ax then
copy to x mov ax,t yt , keep value of t in
ax mov bx,y next instruction will copy to
y mov bx,ax after this i and j should be
exchanged value
13
pop bx restore content of bx mov
sp,bp pop bp ret 4 swap endp main proc ne
ar mov ax,_at_data mov ds,ax lea ax,i pass
parameters (Pascal Convention) push ax
lea ax,j push ax call swap call
swap mov ax,4c00h int 21h main endp end main
14
???? nested call ???? recursive call ???? main
call A ???? A call B main call A proc
A call B proc B ?????? stack
frame ?? stack ?????? ???????? ????????? dynamic
link ??? stack frame pointer
15
bp ??? main ???????? ????? bp
stack frame ??? A
bp stack
frame ??? B
Write a Comment
User Comments (0)
About PowerShow.com