LAB‎ > ‎

Lab 6

6. Activation Record
1) 다음 프로그램을 LMC assembly language로 핸드컴파일 한 후 실행하시오.

main() {

   int n, v1, v2;

   v1=asm(IN);

   v2=asm(IN);

   n=sub_two(v1,v2);

   asm(OUT,n);

}


int sub_two(int a, int b) {

   int tmp;

   int result;

   tmp = -b;

   result = a + tmp;

   return result;

}


아래 프로그램 중 int sub_two() 부분을 완성하면 된다. 
// Sub_two, V07
ORG0
RUNTIMELDABOTTOM// SP <-- BOTTOM
SWAPASP
LDA#0// LD B #0
SWAPAB
SWAPASP// room for return value
DECA// of MAIN
SWAPASP
SETRTN// CALL MAIN
SWAPAR
ADDA#4
SWAPAR
PUSHR
JMPMAIN
COB
MAINSWAPAB// PUSH B
PUSHA
MOVBSP// MOV B SP
SWAPASP// room for local variable
SUBA#3// int n,v1,v2;
SWAPASP
// PUSHALL// save visible registers
SWAPASP// room for return value
DECA// of F_SUB_TWO
SWAPASP
IN
STA%-2// v1=
IN
STA%-1// v2=
LDA%-1
PUSHA// pass parameter, (v2)
LDA%-2
PUSHA// pass parameter, (v1)
SETRTN// CALL F_SUB_TWO
SWAPAR
ADDA#4
SWAPAR
PUSHR
JMPF_SUB_TWO
RTN1SWAPASP// remove used arguments
ADDA#2// 2개(a,b)
SWAPASP
POPA// get return value
STA%-3// n=
LDA%-3// asm(OUT,n)
OUT
// POPALL// restore visible registers
MOVSPB// MOV SP B
POPA// POP B
SWAPAB
POPR// RETURN
JMP*R
F_SUB_TWO
. . .
ORG99
BOTTOMBOXBOTTOM



Comments