彙編 題目 22,23 子程式呼叫

2021-10-10 14:55:43 字數 2829 閱讀 4688

在多模組設計中,主模組中呼叫內部模組buf1,buf2,buf3,buf4。主模組根據鍵盤輸入的指令(如:a,b,c,d)呼叫上述對應的子程式,每個子程式的任務是顯示其入口位址。呼叫後繼續等待呼叫,若輸入esc鍵(ascii碼為1bh)則結束程式的執行。請編寫完成該任務的程式。

現有一控制程式共5個工序,要求輸入0-4的序號,分別執行各工序的子程式,每個子程式的任務是顯示其入口位址。呼叫後繼續等待呼叫,按回車則結束程式的執行。

datas segment

;此處輸入資料段**

buf0 db 0ah,

'please choose the subprogram(a,b,c,d): '

,'$'

buf dw buf1,buf2,buf3,buf4

datas ends

stacks segment

;此處輸入堆疊段**

stacks ends

codes segment

assume cs:codes,ds:datas,ss:stacks;==

====

====

====

====

====

main proc far

mov ax,datas

mov ds,ax

loop_begin:

mov dx,offset buf0

mov ah,

09h int

21h mov ah,

01h int

21h cmp al,

'a' je one

cmp al,

'b' je two

cmp al,

'c' je three

cmp al,

'd' je four

cmp al,

1bh je exit0

jmp loop_begin

one:

call buf1

jmp loop_begin

two:

call buf2

jmp loop_begin

three:

call buf3

jmp loop_begin

four:

call buf4

jmp loop_begin

exit0:

mov ah,

4ch int 21h

main endp;==

====

====

====

====

====

buf1 proc near

mov bx,offset buf1

call output

retbuf1 endp;==

====

====

====

====

====

==buf2 proc near

mov bx,offset buf2

call output

retbuf2 endp;==

====

====

====

====

====

==buf3 proc near

mov bx,offset buf3

call output

retbuf3 endp;==

====

====

====

====

====

==buf4 proc near

mov bx,offset buf4

call output

retbuf4 endp;==

====

====

====

====

====

==output proc near

mov dx,

0ah mov ah,

02h int

21h mov dx,bx

mov cl,

4 shr dh,

4 add dh,

30h cmp dh,

39h jle first

add dh,

7first:

mov dl,dh

mov ah,

02h int

21h mov dh,bh

and dh,

0fh add dh,

30h cmp dh,

39h jle second

add dh,

7second:

mov dl,dh

mov ah,

02h int

21h mov dl,bl

shr dl,cl

add dl,

30h cmp dl,

39h jle third

add dl,

7third:

mov ah,

02h int

21h mov dl,bl

and dl,

0fh add dl,

30h cmp dl,

39h jle forth

add dl,

7forth:

mov ah,

02h int

21h ret

output endp

codes ends

end main

組合語言 子程式呼叫

不是很常用的 子程式返回指令 說明 根據段內和段間 有無引數,具體分成4種情況 1 ret 無引數返回 2 ret n 有引數返回 n引數的作用 需要彈出call指令壓入堆疊的返回位址 3 段內返回 偏移位址ip出棧 ip ss sp sp sp 2 4 段間返回 偏移位址ip和段位址cs出棧 ip...

COBOL子程式呼叫

內部子程式 identification division.program id.proc a.environment division.data division.procedure division.identification division.program id.proc b.enviro...

COBOL子程式呼叫

內部子程式 identification division.program id.proc a.environment division.data division.procedure division.identification division.program id.proc b.enviro...