CS 225 Assembly Language Programming Midterm exam October 17, 2008 Due beginning of class Friday, October 24, 2008, Day 24 CORRECTIONS p. 3&5 Open book, notes. This is mostly short answers; but a few parts (and the programs) may take longer. Do it in pieces; start now! You may ask me questions; I may answer or decline to answer, or I may be willing to sell you a hint for a certain number of points. Except for programs,(9 and 10) Put your answers on these pages (or attached if you need more room) ___________________NAME_____________________ 1) Assume 12-bit registers for this problem: (You may want to translate to binary and back to hex. Show your work.) a) Find the hex representation of Not (2BEH) b) Find the hex representation of (2BEH) OR Not(2BEH) c) Find the hex representation of (BEEH) AND (F0BH) ____________________________ 2) In the PEP8 system our memory is byte-addressable. Every byte has its own address. Our addresses are 16 bits long (2 bytes), and the addresses go from 0000 to FFFF. You are designing a very small, specialized computer system in which each set of 4 bits (= a "nibble" = half a byte) needs its own address. You will use 7-bit addresses. i) How many different addresses are possible? (in decimal) ii) What is the lowest address? The highest address? (Give your answers in hex) iii) How many bits can you have of addressable memory? How many bytes? CS225 midterm '08 p. 2 3) Assume we have a computer which works with 10-bit integers. a) i) What are the smallest and largest Unsigned Decimal numbers which can be represented? ii) What are the smallest and largest (2's complement) Signed Decimal numbers which can be represented? b) i)What is 10 0001 11112 (a binary number) represented as a Hex number? ii) What is 10 0001 11112 represented as an Unsigned Decimal number? iii) What is the two's complement of 10 0001 11112? (Binary) iii) What is 10 0001 11112 represented as a (two's complement) Signed Decimal number? Explain your work c) Do the following operations in Binary. Convert each number to unsigned and signed Decimal and "check" the operation. Then give the values of the NZVC flags at the end of the operation. i) binary = unsigned decimal = =________________ = signed decimal = _____________ = flags N Z V C 10 0001 1111 + 10 0001 0000 Computer sum is Decimal Sum should be ii) binary = unsigned decimal = =________________ = signed decimal = _____________ = flags N Z V C 10 0001 1111 + 01 0000 0001 Computer sum is Decimal Sum should be CS225 midterm '08 p. 3 ______________________________________________________________ 4) Assume this is the state of the machine at the beginning of each instruction. Memory contents (viewed as bytes, in hex) HERE Address Contents Address Contents 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 Y 000A 000B 09 FBC5 FF FBC6 03 FBC7 70 FBC8 50 FBC9 07 FBCA 38 FBCB 00 FBCC 01 26 FBCD 00 FBCE 00 FBCF FF 05 X 70 1230 41 07 SP FBCA B0 00 20 10 00 00 Registers A ABCD HERE is a symbol for 0005 Y is a symbol for 000A Assume Each instruction is at address 0102H. that is, the code for lda -1,s begins at 0102; the code for lda 2, s begins at 0102, etc.. (remember this is not a sequence of instructions!) For each instruction, show what it does by entering the new number in any column where the number is changed. For instance, if the value of the word at memory address 0002 is changed to 2223, 0002 and 0003 are entered under Memory addresses (top half), 22 and 23 under Memory byte contents (bottom half). If register A becomes ABFF, fill in the Reg.A box. Leave unchanged boxes empty. Remember, Assume the above is the state of the machine at the beginning of each instruction. Memory Address(es)/byte contents Reg. A Reg. X SP lda -1, s lda 2, s (yes) sta HERE, d stbytea Y, d ldbytex HERE, d ldbytex HERE, i call HERE addsp 3, i CS225 midterm '08 p. 4 5) Assume this is the state of the machine at the beginning of each problem HERE Address Contents 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 Y 000A 000B 09 FF X 03 70 0003 50 07 38 00 01 26 00 00 Registers A ABCD HERE is a symbol for 0005. Y is a symbol for 000A For each piece of code, tell whether it will Branch (Yes) or continue with the next instruction (No). cpa 0xABCE, i BRLT Yes No: ~~~~~~~ a) b) lda 0x0001, d BRLT Yes No: ~~~~~~~ ldbytea Y, d BREQ Yes No: ~~~~~~~ c) d) lda 0x0007, d suba 1, i BREQ Yes No: ~~~~~~~ e) lda 0x000A, d ldx 0x0004, d BREQ Yes No: ~~~~~~~ f) lda 0x000A, d ldx 0x0004, d cpa 0, i BREQ Yes No: ~~~~~~~ CS225 midterm '08 p. 5 6) a) Assume that this chunk of memory consists only of PEP8 instructions, not data. Translate it to Assembly Language. How? Front cover of book. (It runs, but is a silly program.) Address 0000 0001 0002 0003 0004 0005 0006 0007 Contents (hex) C1 00 03 04 00 07 18 00 (Object program is C1 00 03 04 00 07 18 00 zz) b) What is in the A register at the end of running this program? ______________________________________________________________ 7) A nonsense program: You can do the problem without running it, or run it to confirm. Addr Code Symbol Mnemon Operand Comment 0000 040017 BR main ;- - - - unum: .EQUATE 0 0003 680002 one: SUBSP 2,i 0006 C006F0 LDA 1776,i 0009 E30000 STA unum,s 000C 160013 CALL two 000F 600002 ADDSP 2,i 0012 5A RET2 RET0 ;- - - - - - 0013 3B0002 two: DECO 2,s 0016 58 RET0 ;------------0017 160003 main: CALL one 001A 00 STOP .END a)Assuming all these addresses contain 0 at the start of the program, fill in their contents at the end of the run. Address FBC7 FBC8 FBC9 FBCA FBCB FBCC FBCD FBCE FBCF Contents b) What part of the stack is the stack frame for procedure one? (Give addresses or mark just above.) c) What part of the stack is the stack frame for procedure two? (Give addresses or mark just above.) d) One instruction in the program violates Warford’s conventions about procedure structuring. Which one and what does it do that’s “wrong”? -- Do it with RET0 at line 12. if you have RET2 at line 12! Then, extra credit for explaining what happens CS225 midterm '08 p. 6 ______________________________________ 8) Instruction Set Architectures sometimes are missing common instructions, which then must be worked around. Suppose the PEP8 ISA has an ASL (true) but does not have ROL (in fact it does). Write a short sequence of PEP8 code which will do the equivalent of ROL (rotate left), but not using the actual ROL. Assume the number to be shifted is in the A register. Leave the result in A. (It does not have to make the flags work "correctly." That's much harder.) ______________________________ 9) Finish writing and debugging this simple program. (This code is also at aurora.wells.edu/~srs/CS225-Fall08/Midtermfile.htm) Email me the program, and hand in the printed Listing. br main Q: .ascii “Do you like Assembly Language? y or n \x00” AYes: .ascii “ I do too! \x00” ANo: .ascii “ I'm sorry! \x00” main: ;Output the string at Q, then input a character. ;If the character is y, output the string at AYes. ;Otherwise, output the string at ANo. __________________________________________ 10) Write a program to count to n: Get a decimal number n from the user. Then output the numbers up to and including n, (space after each one) and finish with an exclamation mark. If 6 is input, the output should be 123456! The “variables” you use should be values on the stack; space should be allocated beforehand and deallocated at the end for them. Email me the program, and hand in the printed Listing. PARTIAL CREDIT: Write the program with no use of the stack, that is, with the “variable(s)” in memory spaces right before the program code (as we did in Chapter 5).
Pages to are hidden for
"CS 225 Assembly Language Programming Midterm exam Nov.1"Please download to view full document