Chapter 6 - solution for exercise 6 j.warford PDF

Title Chapter 6 - solution for exercise 6 j.warford
Author Tapan Patel
Course computer systems architechture
Institution Harrisburg University of Science and Technology
Pages 2
File Size 83.9 KB
File Type PDF
Total Downloads 119
Total Views 170

Summary

solution for exercise 6 j.warford...


Description

Chapter 6 Section 6.1 Exercise: 1 Explain the difference in the C memory model between global and local variable. How is each allocation and accessed? The difference between local variable and global variable is the local variable declared inside a function whereas the variable declared outside the function is known as global variable. In the starting of an execution local variable are created and are lost when the function terminates, on the other hand in execution started global variables are created and lost when the program ends. Local variable is push locals with SUBSP and access with stack-relative addressing mode. Local variables pop locals with ADDSP. Call-by-value with local variables: In call by value with local variables for getting an actual parameter in the caller generate load with stack-relative addressing(s) and to get formal parameter in the callee generate load with stack relative addressing(s). To call a non-void function in C: In call a non-void function push storage for return value and push actual parameters and address. Also pushing storage for the local variable Call-by-reference with global variables: in the Call-by-reference with global variables difference by Call-by-value with local variables is here to get actual parameters in the caller, generate load with immediate addressing(i). And to get the formal parameter x in the callee generate load with stack-relative addressing (s) in addition to this to get the unreferenced formal parameter *x in the callee, generate load with stack-relative deferred addressing (sf) Call-by-reference with local variables: unary MOVSPA followed by ADDA parameter x in the callee, generate unreferenced formal parameter *x in addressing (sf)

To get the actual parameter in the caller, generate the with immediate addressing (i) and to get the formal load with stack-relative addressing (s). To get the the callee, generate load with stack-relative deferred

Section 6.4 Exercise: 8 In the Pep/9 program figure, if you enter 4 for Guess, what statement execute after the branch at 0010? Why? Branch address is calculated as Oprnd = Mem[OprndSpec + X] =Mem[0013+8] =Mem[001B] = 4900 We can’t tell from program listing in which bit are at 4900, but assuming that they are all zeros 0’s In von Neumann cycle interprets the 00 at address 4900 as the STOP instruction.

Section 6.2 Problem: 11 Translate the following C program to pep/9 assembly language #include void main() { int num1, rem1; printf("Input an integer : "); scanf("%d", &num1); rem1 = num1 % 2; if (rem1 == 0) printf("%d is an even integer\n", num1); else printf("%d is an odd integer\n", num1); }

BR main num: .EQUATE 0

;local variable #2d

main: SUBSP 2,i ;allocate #num DECI num,s ;cin >> num if: LDWA num,s ;if (num != 1) ANDA 0x0001,i BRNE else STRO even_msg,d ;cout...


Similar Free PDFs