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

PLEASE ANSWER AND SHOW WORK IF NECCASARY. Brief Discussion: (20 pts) 10. (5 pts)

ID: 3920323 • Letter: P

Question

PLEASE ANSWER AND SHOW WORK IF NECCASARY.

Brief Discussion: (20 pts) 10. (5 pts) Briefly explain why global variables are better (or not) for debugging inline assembly code. 11. (10 pts) For homework #9, we used an array of pointers for our wordlist. It is the same data type as "Char argvI" used by main in a C/C++ program. Assume the following declaration is made in C: char "gwordList I "hello", "huh?", "apple", "study", "party", "767", "!YEAH!" a. How many bytes are used to hold the variable gWordList? b. How many elements in the array gWordList? c. Write the assembly instruction(s) to get the address of the word "study" d. How many bytes will the compiler use to store the word "party" What must be done before we could use our binary search algorithm to find a word in this list? e. 12. (5 pts) Briefly describe a debugging approach you could use to debug inline assembly 2017 01-CS 3843 Computer Organization-Exam #3 Page 2

Explanation / Answer

Breifly explain why global variables are better(or not) for debugging inline assembly code.
When the compiler optimizes code, it repositions and reorganizes instructions. This results in more efficient compiled code. Because of this rearrangement, the debugger cannot always identify the source code that corresponds to a set of instructions.

Optimization can affect:

Local variables, which can be removed by the optimizer or moved to locations the debugger does not understand.

Positions inside a function, which are changed when the optimizer merges blocks of code.

Function names for frames on the call stack, which might be wrong if the optimizer merges two functions.

The frames that you see on the call stack are almost always correct, however, assuming you have symbols for all frames. The frames on the call stack will be wrong if you have stack corruption, if you have functions written in assembly language, or if there are operating system frames without matching symbols on the call stack.

Global and static variables are always shown correctly. So is structure layout. If you have a pointer to a structure and the value of the pointer is correct, every member variable of the structure will show the correct value.
Safely accessing C data and calling functions from basic asm is more complex than it may appear. To access C data, it is better to use extended asm.

Do not expect a sequence of asm statements to remain perfectly consecutive after compilation. If certain instructions need to remain consecutive in the output, put them in a single multi-instruction asm statement. Note that GCC’s optimizers can move asm statements relative to other code, including across jumps.

asm statements may not perform jumps into other asm statements. GCC does not know about these jumps, and therefore cannot take account of them when deciding how to optimize. Jumps from asm to C labels are only supported in extended asm.

Under certain circumstances, GCC may duplicate (or remove duplicates of) your assembly code when optimizing. This can lead to unexpected duplicate symbol errors during compilation if your assembly code defines symbols or labels.

Since GCC does not parse the AssemblerInstructions, it has no visibility of any symbols it references. This may result in GCC discarding those symbols as unreferenced.

The compiler copies the assembler instructions in a basic asm verbatim to the assembly language output file, without processing dialects or any of the % operators that are available with extended asm. This results in minor differences between basic asm strings and extended asm templates. For example, to refer to registers you might use %eax in basic asm and %%eax in extended asm.
Assembler Instructions with C Expression Operands:
asm [volatile] ( ``AssemblerTemplate``
: ``OutputOperands``
[ : ``InputOperands``
[ : ``Clobbers`` ] ])

asm [volatile] goto ( ``AssemblerTemplate``
:
: ``InputOperands``
: ``Clobbers``
: ``GotoLabels``)

char *gwordlist[]={"hello","huh?","apple","study","party","767","!yeah1"};

a.how many bytes are used to hold the variable gworldlist is === 8.

b.array index starts with "0" so the elements in arraylist is 6 i.e 0,1,2,3,4,5.

c.Assembly Instruction:

tmpval: Study

__start:
gwordlist $sp,$sp 6
sw $returnaddr, 0($sp) # Return addy
sw $t0, 3($sp)
sw $t1, 6($sp)

la $t0, tmpval
lw $t1, 0($t0)  
gwordlist $t1, $3  
sw $t1, 0($t0)

lw $ra, 0($sp)
lw $t0, 4($sp)
lw $t1, 6($sp)
add $sp, $sp, 6
jr $ra

Here la(loadadress),lw(loadword),sw(storeword),ra(resultaddrr),$somevariable(registers).

d."1 byte" it takes to complier to store an "party" word.

e.what must be done before we could use our binary search algorthim to find a word in this list.
Ans.First we need to analyze the arraylist size and then we follow th below pseudo code.
Let min = 0 and max = n-1.
Compute guess as the average of max and min, rounded down (so that it is an integer).
If array[guess] equals target, then stop. You found it! Return guess.
If the guess was too low, that is, array[guess] < target, then set min = guess + 1.
Otherwise, the guess was too high. Set max = guess - 1.
Go back to step 2.

Breifly describe a debugger appoarch you could use for debug inline Assembly.

Within the debugger, you can set breakpoints on both C or C++ and assembly-language lines. If you enable mixed assembly and source mode, you can display both the source and disassembled form of the assembly code.

Note that putting multiple assembly instructions or source language statements on one line can hamper debugging. In source mode, you can use the debugger to set breakpoints on a single line but not on individual statements on the same line. The same principle applies to an __asm block defined as a C macro, which expands to a single logical line.

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