Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For the problems given, develop MIPS programs that satisfy the specifications in

ID: 3816550 • Letter: F

Question

For the problems given, develop MIPS programs that satisfy the specifications in the problem statement. Remember: To turn in this homework, email your NotePad files of the programs as attachments to the TA. Note: these are more advanced problems, and deserve careful consideration and focus.

1. (CLO 5—Assy Lang.) Develop a program that arranges the series of decimal numbers shown in ascending order from smallest to largest, then prints them out. If you wish, you can copy and paste the program in the space to your left so that you will have a printed record of it. When the numbers are printed, put a carriage return/line feed between each, for neatness. Note 1: You will not need any counters, as the data provided has a final zero value, so that all you have to do is test for 0 and then quit. Note that the 0 is NOT to be printed out—it is not a value to be compared but merely an “edge” to tell you that the list is over. Note 2: This must be a recursive program.

2. (CLO 5—Assy Lang.) Compose a program to initialize an array with a series of numbers. This program will be very similar to one that we did in class, but with a twist or two. The array is to be 20 X 20 words, so you will need to use the “.space” command to initialize the array size. It should be 400 words (20 X 20), but remember, using the “.space” directive, you have to reserve bytes. In this case, you are going to load each row of the array with slightly different numbers. You will be loading rows 0-19, and columns 0-19, or 20 X 20. Remember that the first row is 0! For even rows (including 0, that is, 0, 2, 4, 6, etc.), load the numbers 1-20 consecutively in the 20 columns. For odd rows (1, 3, 5, 7, etc.) load the numbers 20-1 consecutively, that is, in reverse order. Thus, you will load even rows with the sequence 1-20, and odd rows with the sequence 20-1. As in problem one, you can print out and paste a copy of the program in the space at the right for your records.

3. (CLO 5—Assy Lang.) Compose a program to arrange the characters in “Hello, world! ” in numerical order, smallest value to largest, and print out the result. That will of course mean that the string of characters looks more or less like gibberish, but the characters will be in proper numerical order, smallest to largest. Note that this requires a recursive program to be done properly. As for the other two problems in this set, you can paste a copy of the program to the right for your records, if you wish.

Explanation / Answer

1. sorting ascending number from the memory LXI H,3000; //load register pair HL with 3000 immediate data to locate the memory address location and move immediate data into the memory. MVI M,80; INX H; //increment register pair HL data by one to load the next memory location and store the next data of the data array. MVI M,75; INX H; MVI M,45; INX H; MVI M,85; INX H; MVI M,35; INX H; MVI M,55; INX H; MVI M,74; INX H; MVI M,27; INX H; MVI M,90; INX H; MVI M,52; MVI C,9; //move 9h immediate data into register C as the counter of the total number of the data array REPEAT: //REPEAT loop is created to move register C data to register D and load the register pair HL with 3000 immediate data to locate the memory address. MOV D,C LXI H,3000 LOOP: //sort the data from the smallest to the largest.This loop function consists of moving memory data to register A, increment register pair HL data by one and compare register A data with memory data. MOV A,M INX H CMP M JC SKIP //jump to SKIP loop if the carry flag is equal 1 and move memory data to register B as a temperary location for the data to stored in. MOV B,M MOV M,A DCX H MOV M,B INX H SKIP: DCR D JNZ LOOP DCR C JNZ REPEAT HLT 2. .DATA PROMPT DB 'The contents of the 2D array are : ',0DH,0AH,'$' ARRAY :.space 800 //400 words or 800 bytes ARRAY DW 0,2,4,6,8,10,12,14,16,18,20 DW 1,3,5,7,9,11,13,15,17,19 DW 0,2,4,6,8,10,12,14,16,18,20 DW 1,3,5,7,9,11,13,15,17,19 DW 0,2,4,6,8,10,12,14,16,18,20 DW 1,3,5,7,9,11,13,15,17,19 .CODE MAIN PROC MOV AX, @DATA ; initialize DS MOV DS, AX LEA DX, PROMPT ; load and display the string PROMPT MOV AH, 9 INT 21H LEA SI, ARRAY ; set SI=offset address of ARRAY MOV BH, 5 ; set BH=5 MOV BL, 5 ; set BL=5 CALL PRINT_2D_ARRAY ; call the procedure PRINT_2D_ARRAY MOV AH, 4CH ; return control to DOS INT 21H MAIN ENDP ;------------------------- Procedure Definitions ------------------------; PRINT_2D_ARRAY PROC ; this procedure will print the given 2D array ; input : SI=offset address of the 2D array ; : BH=number of rows ; : BL=number of columns ; output : none PUSH AX ; push BX onto the STACK PUSH CX ; push CX onto the STACK PUSH DX ; push DX onto the STACK PUSH SI ; push SI onto the STACK MOV CX, BX ; set CX=BX @OUTER_LOOP: ; loop label MOV CL, BL ; set CL=BL @INNER_LOOP: ; loop label MOV AH, 2 ; set output function MOV DL, 20H ; set DL=20H INT 21H ; print a character MOV AX, [SI] ; set AX=[SI] CALL OUTDEC ; call the procedure OUTDEC ADD SI, 2 ; set SI=SI+2 DEC CL ; set CL=CL-1 JNZ @INNER_LOOP ; jump to label @INNER_LOOP if CL!=0 MOV AH, 2 ; set output function MOV DL, 0DH ; set DL=0DH INT 21H ; print a character MOV DL, 0AH ; set DL=0AH INT 21H ; print a character DEC CH ; set CH=CH-1 JNZ @OUTER_LOOP ; jump to label @OUTER_LOOP if CX!=0 POP SI ; pop a value from STACK into SI POP DX ; pop a value from STACK into DX POP CX ; pop a value from STACK into CX POP AX ; pop a value from STACK into AX RET PRINT_2D_ARRAY ENDP 3.arrange cgaracters of string in alphabetical order check macro a, b local next, finish cld mov cx, 64 ; the size of our buffer that saves the string mov si, a mov di, b repe cmpsb ; comparing two strings with each other ja next jmp finish next: ; swaping our strings if needed mov cx, 64 mov si, a lea di, change rep movsb mov cx, 64 mov si, b mov di, a rep movsb mov cx, 64 lea si, change mov di, b rep movsb finish: endm