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

Assembly Language Program: You are in a team that writes a program that is going

ID: 3772494 • Letter: A

Question

Assembly Language Program:

You are in a team that writes a program that is going to require a list of coordinates to plot a graph. Your manager gives you the job to create a set of procedures that will generate that list of coordinates. You are also going to have to write code that will test the functionality of your procedures, before handling them to your team.

Specifics:

Write a procedure called arrayFill that will fill a 16x16 array, called main array, with random numbers in the range of 0 to 100. This procedure has to take stack parameters: the array address, length and type.

The same procedure should fill a 1x8 array, called target array, with random numbers in the range of 1 to 100.

Write a procedure called PrintArray that will print the main array. This procedure should be called with the INVOKE directive and should have an argument list. The same procedure has to print the target array as well.

Write a procedure called ProcessArray that will search the main array looking for any value that is equal with a value in the target array. Once you have found a number you should INVOKE a procedure called PrintCoord to print the found number, the row, and column location in the main array. At the same time, replace the number found in the main array with 1000, to mark it. This means, when ProcessArray procedure finishes it should produce a list of coordinates that your team can use to plot the graph and the main array will have locations with the number 1000 which mark the found coordinates.

After the ProcessArray procedure finishes, invoke again the PrintArray procedure to print your main array to show the replaced values.

So, your program should flow in this order

call arrayFill, to fill the main array with random numbers

invoke PrintArray, to print the main array in a 16x16 format

call arrayFill, to fill the target array with random numbers

invoke PrintArray, to print the target array in a 1x8 format

invoke ProcessArray, to process the main array as shown above.

Inside this procedure invoke PrintCoord to print each found values and coordinates

invoke PrintArray, to print the main array in a 16x16 format

Make sure to write some messages so that the output is clear to the user. See my examples below.

Requirements

Your procedures should be able to work with any array size and any number of rows or columns. If I change the main array to 8x2 and the target array 1x2, your program should work the same. See my example below.

The columns and rows start from 0. So, for an array with 16 columns, as an example, the column number will be printed from 0 to 15.

fillArray has to use stack parameters, while the other procedures use the INVOKE directive and arguments.

No hard coded numbers are allowed, except the 1000 number and the stack access pointers (like [ebp + 16]).

Don't forget to Randomize at the beginning of your program.

Example 1, 16x16 main array and 1x8 target array:

Example 2, 8x2 main array and 1x2 target array:

Extra Credit 1: 10 points

For those of you who like a bit of challenge here is a way towards some extra credit:

The program, as described, has a problem. If no match between arrays was found it will still print "Here are the found values and coordinates" and "Main Array After Sort". If the procedure ProcessArray finds no matching value, print a message that no values were found and end the program, so that the main array will not be printed twice. (Hint: You can test your code with the 8x2 and 1x2 arrays, because the smaller the arrays the least chance to hit matching numbers.)

Extra Credit 2: 10 points

Write some code that will print the number of found coordinates, after the main array was processed and the coordinates printed, so that your team will know how many points are there to plot.

Explanation / Answer

.Ltext0:
                    .comm   i,4,4
                    .comm   j,4,4
                    .comm   k,4,4
                    .comm   l,4,4
                    .comm   randNum,4,4
                    .comm   mainItem,4,4
                    .comm   tgtItem,4,4
                    .globl   mainDim1
                    .data
                    .align 4
                mainDim1:
0000 08000000        .long   8
                    .globl   mainDim2
                    .align 4
                mainDim2:
0004 02000000        .long   2
                    .globl   tgtDim1
                    .align 4
                tgtDim1:
0008 01000000        .long   1
                    .globl   tgtDim2
                    .align 4
                tgtDim2:
000c 02000000        .long   2
                    .comm   mainArray,1024,32
                    .comm   targetArray,32,32
                    .section   .rodata
                .LC0:
0000 0A204D61        .string   " Main Array elements: "
     696E2041
     72726179
     20656C65
     6D656E74
                .LC1:
001a 256400         .string   "%d"
                .LC2:
001d 202C2000        .string   " , "
0021 00000000        .align 8
     000000
                .LC3:
0028 0A205072        .string   " Printing Target Array elements: "
     696E7469
     6E672054
     61726765
     74204172
                    .text
                    .globl   procedurePrintArray
                procedurePrintArray:
                .LFB0:
                    .cfi_startproc
0000 55              pushq   %rbp
                    .cfi_def_cfa_offset 16
                    .cfi_offset 6, -16
0001 4889E5         movq   %rsp, %rbp
                    .cfi_def_cfa_register 6
0004 BF000000        movl   $.LC0, %edi
     00
0009 B8000000        movl   $0, %eax
     00
000e E8000000        call   printf
     00
0013 C7050000        movl   $0, i(%rip)
     00000000
     0000
001d E9830000        jmp   .L2
     00
                .L5:
0022 C7050000        movl   $0, j(%rip)
     00000000
     0000
002c EB4E            jmp   .L3
                .L4:
006d 8B050000        movl   j(%rip), %eax
     0000
0073 83C001         addl   $1, %eax
0076 89050000        movl   %eax, j(%rip)
     0000
002e 8B150000        movl   i(%rip), %edx
     0000
0034 8B050000        movl   j(%rip), %eax
     0000
003a 4898            cltq
003c 4863D2         movslq   %edx, %rdx
003f 48C1E204        salq   $4, %rdx
0043 4801D0         addq   %rdx, %rax
0046 8B048500        movl   mainArray(,%rax,4), %eax
     000000
004d 89C6            movl   %eax, %esi
004f BF000000        movl   $.LC1, %edi
     00
0054 B8000000        movl   $0, %eax
     00
0059 E8000000        call   printf
     00
005e BF000000        movl   $.LC2, %edi
     00
0063 B8000000        movl   $0, %eax
     00
0068 E8000000        call   printf
     00
                .L3:
0096 8B050000        movl   i(%rip), %eax
     0000
009c 83C001         addl   $1, %eax
009f 89050000        movl   %eax, i(%rip)
     0000
007c 8B150000        movl   j(%rip), %edx
     0000
0082 8B050000        movl   mainDim2(%rip), %eax
     0000
0088 39C2            cmpl   %eax, %edx
008a 7CA2            jl   .L4
008c BF0A0000        movl   $10, %edi
     00
0091 E8000000        call   putchar
     00
                .L2:
00a5 8B150000        movl   i(%rip), %edx
     0000
00ab 8B050000        movl   mainDim1(%rip), %eax
     0000
00b1 39C2            cmpl   %eax, %edx
00b3 0F8C69FF        jl   .L5
     FFFF
00b9 BF000000        movl   $.LC3, %edi
     00
00be B8000000        movl   $0, %eax
     00
00c3 E8000000        call   printf
     00
00c8 C7050000        movl   $0, i(%rip)
     00000000
     0000
00d2 E9830000        jmp   .L6
     00
                .L9:
00d7 C7050000        movl   $0, j(%rip)
     00000000
     0000
00e1 EB4E            jmp   .L7
                .L8:
0122 8B050000        movl   j(%rip), %eax
     0000
0128 83C001         addl   $1, %eax
012b 89050000        movl   %eax, j(%rip)
     0000
00e3 8B150000        movl   i(%rip), %edx
     0000
00e9 8B050000        movl   j(%rip), %eax
     0000
00ef 4898            cltq
00f1 4863D2         movslq   %edx, %rdx
00f4 48C1E203        salq   $3, %rdx
00f8 4801D0         addq   %rdx, %rax
00fb 8B048500        movl   targetArray(,%rax,4), %eax
     000000
0102 89C6            movl   %eax, %esi
0104 BF000000        movl   $.LC1, %edi
     00
0109 B8000000        movl   $0, %eax
     00
010e E8000000        call   printf
     00
0113 BF000000        movl   $.LC2, %edi
     00
0118 B8000000        movl   $0, %eax
     00
011d E8000000        call   printf
     00
                .L7:
014b 8B050000        movl   i(%rip), %eax
     0000
0151 83C001         addl   $1, %eax
0154 89050000        movl   %eax, i(%rip)
     0000
0131 8B150000        movl   j(%rip), %edx
     0000
0137 8B050000        movl   tgtDim2(%rip), %eax
     0000
013d 39C2            cmpl   %eax, %edx
013f 7CA2            jl   .L8
0141 BF0A0000        movl   $10, %edi
     00
0146 E8000000        call   putchar
     00
                .L6:
015a 8B150000        movl   i(%rip), %edx
     0000
0160 8B050000        movl   tgtDim1(%rip), %eax
     0000
0166 39C2            cmpl   %eax, %edx
0168 0F8C69FF        jl   .L9
     FFFF
016e 5D              popq   %rbp
                    .cfi_def_cfa 7, 8
016f C3              ret
                    .cfi_endproc
                .LFE0:
                    .globl   procedureArrayFill
                procedureArrayFill:
                .LFB1:
                    .cfi_startproc
0170 55              pushq   %rbp
                    .cfi_def_cfa_offset 16
                    .cfi_offset 6, -16
0171 4889E5         movq   %rsp, %rbp
                    .cfi_def_cfa_register 6
0174 C7050000        movl   $0, i(%rip)
     00000000
     0000
017e E9C00000        jmp   .L11
     00
                .L14:
0183 C7050000        movl   $0, j(%rip)
     00000000
     0000
018d E9840000        jmp   .L12
     00
                .L13:
0207 8B050000        movl   j(%rip), %eax
     0000
020d 83C001         addl   $1, %eax
0210 89050000        movl   %eax, j(%rip)
     0000
0192 E8000000        call   rand
     00
0197 89C1            movl   %eax, %ecx
0199 BA1F85EB        movl   $1374389535, %edx
     51
019e 89C8            movl   %ecx, %eax
01a0 F7EA            imull   %edx
01a2 C1FA05         sarl   $5, %edx
01a5 89C8            movl   %ecx, %eax
01a7 C1F81F         sarl   $31, %eax
01aa 29C2            subl   %eax, %edx
01ac 89D0            movl   %edx, %eax
01ae 6BC064         imull   $100, %eax, %eax
01b1 29C1            subl   %eax, %ecx
01b3 89C8            movl   %ecx, %eax
01b5 89050000        movl   %eax, randNum(%rip)
     0000
01bb 8B0D0000        movl   i(%rip), %ecx
     0000
01c1 8B150000        movl   j(%rip), %edx
     0000
01c7 8B050000        movl   randNum(%rip), %eax
     0000
01cd 4863D2         movslq   %edx, %rdx
01d0 4863C9         movslq   %ecx, %rcx
01d3 48C1E104        salq   $4, %rcx
01d7 4801CA         addq   %rcx, %rdx
01da 89049500        movl   %eax, mainArray(,%rdx,4)
     000000
01e1 8B050000        movl   randNum(%rip), %eax
     0000
01e7 89C6            movl   %eax, %esi
01e9 BF000000        movl   $.LC1, %edi
     00
01ee B8000000        movl   $0, %eax
     00
01f3 E8000000        call   printf
     00
01f8 BF000000        movl   $.LC2, %edi
     00
01fd B8000000        movl   $0, %eax
     00
0202 E8000000        call   printf
     00
                .L12:
0234 8B050000        movl   i(%rip), %eax
     0000
023a 83C001         addl   $1, %eax
023d 89050000        movl   %eax, i(%rip)
     0000
0216 8B150000        movl   j(%rip), %edx
     0000
021c 8B050000        movl   mainDim2(%rip), %eax
     0000
0222 39C2            cmpl   %eax, %edx
0224 0F8C68FF        jl   .L13
     FFFF
022a BF0A0000        movl   $10, %edi
     00
022f E8000000        call   putchar
     00
                .L11:
0243 8B150000        movl   i(%rip), %edx
     0000
0249 8B050000        movl   mainDim1(%rip), %eax
     0000
024f 39C2            cmpl   %eax, %edx
0251 0F8C2CFF        jl   .L14
     FFFF
0257 C7050000        movl   $0, i(%rip)
     00000000
     0000
0261 E9C30000        jmp   .L15
     00
                .L18:
0266 C7050000        movl   $0, j(%rip)
     00000000
     0000
0270 E9870000        jmp   .L16
     00
                .L17:
02ed 8B050000        movl   j(%rip), %eax
     0000
02f3 83C001         addl   $1, %eax
02f6 89050000        movl   %eax, j(%rip)
     0000
0275 E8000000        call   rand
     00
027a 89C1            movl   %eax, %ecx
027c BA1F85EB        movl   $1374389535, %edx
     51
0281 89C8            movl   %ecx, %eax
0283 F7EA            imull   %edx
0285 C1FA05         sarl   $5, %edx
0288 89C8            movl   %ecx, %eax
028a C1F81F         sarl   $31, %eax
028d 29C2            subl   %eax, %edx
028f 89D0            movl   %edx, %eax
0291 6BC064         imull   $100, %eax, %eax
0294 29C1            subl   %eax, %ecx
0296 89C8            movl   %ecx, %eax
0298 83C001         addl   $1, %eax
029b 89050000        movl   %eax, randNum(%rip)
     0000
02a1 8B0D0000        movl   i(%rip), %ecx
     0000
02a7 8B150000        movl   j(%rip), %edx
     0000
02ad 8B050000        movl   randNum(%rip), %eax
     0000
02b3 4863D2         movslq   %edx, %rdx
02b6 4863C9         movslq   %ecx, %rcx
02b9 48C1E103        salq   $3, %rcx
02bd 4801CA         addq   %rcx, %rdx
02c0 89049500        movl   %eax, targetArray(,%rdx,4)
     000000
02c7 8B050000        movl   randNum(%rip), %eax
     0000
02cd 89C6            movl   %eax, %esi
02cf BF000000        movl   $.LC1, %edi
     00
02d4 B8000000        movl   $0, %eax
     00
02d9 E8000000        call   printf
     00
02de BF000000        movl   $.LC2, %edi
     00
02e3 B8000000        movl   $0, %eax
     00
02e8 E8000000        call   printf
     00
                .L16:
031a 8B050000        movl   i(%rip), %eax
     0000
0320 83C001         addl   $1, %eax
0323 89050000        movl   %eax, i(%rip)
     0000
02fc 8B150000        movl   j(%rip), %edx
     0000
0302 8B050000        movl   tgtDim2(%rip), %eax
     0000
0308 39C2            cmpl   %eax, %edx
030a 0F8C65FF        jl   .L17
     FFFF
0310 BF0A0000        movl   $10, %edi
     00
0315 E8000000        call   putchar
     00
                .L15:
0329 8B150000        movl   i(%rip), %edx
     0000
032f 8B050000        movl   tgtDim1(%rip), %eax
     0000
0335 39C2            cmpl   %eax, %edx
0337 0F8C29FF        jl   .L18
     FFFF
033d 5D              popq   %rbp
                    .cfi_def_cfa 7, 8
033e C3              ret
                    .cfi_endproc
                .LFE1:
                    .globl   main
                main:
                .LFB2:
                    .cfi_startproc
033f 55              pushq   %rbp
                    .cfi_def_cfa_offset 16
                    .cfi_offset 6, -16
0340 4889E5         movq   %rsp, %rbp
                    .cfi_def_cfa_register 6
0343 B8000000        movl   $0, %eax
     00
0348 E8000000        call   procedureArrayFill
     00
034d B8000000        movl   $0, %eax
     00
0352 E8000000        call   procedurePrintArray
     00
0357 B8000000        movl   $0, %eax
     00
035c 5D              popq   %rbp
                    .cfi_def_cfa 7, 8
035d C3              ret
                    .cfi_endproc
                .LFE2:
                .Letext0:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote