Assembly Language Programming
Question) Declare the following data structures for a Student Grade database:
a.) Course Name. 30 ASCII characters. Terminate with CR, LF, '$'.
b.) Summary Message: Initial value: "Small U Grade Summary Statistics', CR, LF, '$'
c.) Class Size. Initial value is 20.
d.) Number of Tests (K). Initial value is 5.
e.) Grade Table: (85, 100) is A, (70, 84) is B, (60, 69) is C, (50, 59) is D, (0,49) is F.
f.) Student Names, store as 6-tuples, one for each student: (First Name (30 chars), 0, Last Name (40 chars), 0, Middle Initial (3 chars), 0).
g.) Student Scores: store K-tuples for each student: (Test 1.....Test K). Scores are integers.
h.) Student Grades: store a 2-tuple for each student: (Score, LetterGrade (1 char)).
i.) Grade Summary: store a 2-tuple for each Letter Grade type: (LetterGrade(1 char), Count).
j.) Various Messages: provide space for 20 lines of messages, each message is up to 75 chars long.
Question) Do each of the following problems:
a.) Write a procedure that computes the Fibonacci numbers, defined by: F(0) = 0, F(1) = 1, F(2) = 1, F(N) = F(N-1) + F(N-2), N > 0. Write a test program to check the procedure for accepting values of N from the user and displaying the results of the Fibonacci calculation for N.
b.) Write a procedure to concatenate two string arrays, whose memory addresses and lengths are given to it as arguments in registers.
c.) Write a procedure to insert string B in the middle of string A, from a given position. The new string can occupy a new location in memory. Write a test procedure (Main) that calls your insert procedure.
Question) Do each of the following problems:
a.) Use AND to isolate bits 5, 3, and 2 in a byte (8-bits).
b.) Use OR to set bits 7 and 6 in a byte.
c.) Use XOR to toggle bit 4 and 1 in a byte.
d.) List as many ways as you can to set the AX register to use AND to isolate bits 5, 3, and 2 in a byte (8-bits).
e.) Use OR to set bits 7 and 6 in a byte.
f.) Use XOR to toggle bit 4 and 1 in a byte.
g.) List as many ways as you can to set (clear) the AX register to zero (0000H).
Question) Do each of the following problems:
a.) Find the 2's complement of the following binary value. Express the result in both binary and hex.
1101 1011 0011 1101 1000 1111 0100 1100 0100 1100 1011 1101 1000 1111 1101 0011
b.) What is the decimal value of the (signed) number obtained in (a)?
c.) Create code fragments to multiply EDX:EAX by 16.
d.) Assume EDX contains F9E8D7C6H and CL contains 04. Determine the contents of EDX after the execution of: ROL EDX, CL.
e.) Assume EDX contains F9E8D7C6H and CL contains 04. Determine the contents of EDX after the execution of: RCR EDX, CL.
f.) Assume EDX contains F9E8D7C6H and CL contains 04. Determine the contents of EDX after the execution of: SAL EDX, CL.
g.) Write a code fragment that translates the HLL assignment statement: D = (A - B) * (A + C). In storing the values, assume A, B, C, D are Doubleword variables. Use IMUL for multiplications.
h.) Write a code fragment that converts time, in micro-seconds, stored in the Time into Hours: Minutes: Seconds in EDX: EAX:ECX.
i.) Clear the bit positions 27, 17, 7, 25, 15, 5, 1 in ECX. The remaining bit positions should be unchanged.
Question) Do each of the following problems:
a.) Set ZF if EDX contains an odd number of bits.
b.) Assume the variables A, B, C, contain the values -900, 10, -50, respectively. Write a code fragment to calculate: (A / B) giving a quotient stored in D and a remainder stored in E. Then calculate (C * D) - E. Assume all the values are sized and stored as Double Word.
c.) Write an assembly procedure which prompts the user to enter 15 integers, then computes the sum, and then prints the sum to the screen.
d.) Trace the execution of the following code fragment. When it is entered, the subroutine has 2 pointers, (memory location addresses), to 4 byte values, pushed onto the stack. The instruction XCHG loc1, loc2, swaps (exchanges) the contents of its two argument locations.
SWAP PROC
;; save working registers
push EBP
mov EBP, ESP
push EBX
;; start swapping
mov EBX, [EBP+8]
xchg EAX, [EBX]
mov EBX, [EBP+4]
xchg EAX, [EBX]
mov EBX, [EBP+8]
xchg EAX, [EBX]
;; swapping ends
;; restore working registers
pop EBX
pop EBP
ret 8 ;; clear parameters off stack and return
SWAP ENDP
Question) Determine the errors, if any, in the following program
DW 100H DUP ( )
.DATA
Test DB 50, 100, 150, 200
Answers: DW 34H DUP ( )
.CODE
Start mov AX, 4K
mov AH, AX
sub AX, 2
sub AH, 0123456H
mov BX, AX
add AX, BL
sub 3, EAX
mov EBX, OFFSET DATA
mov AX, (BX)
CODE END
END Start
Question) (Extra Credit) An inventory record for a small business is designed (formatted) as follows.
Location 3 bits
Status 1 bit
Quantity 5 bits
Vendor 4 bits
a.) Declare a .DATA segment variable for an Inventory Record.
b.) Show how to extract the value for Location from the record.
c.) Show how to extract the value of Quantity from the record.
d.) Show how to set Location to the value 3.
e.) Show how to set Status to the value 1.
f.) Show how to add value 6 to Quantity.
g.) Show how to load the Vendor field to EDX.
h.) Show how to toggle the Status.
i.) Show how to zero (clear) all fields in the inventory record.