Exams › GATE › Technical
Consider the given C-code and its corresponding assembly code, with a few operands U1–U4 being unknown. Some useful information as well as the semantics of each unique assembly instruction is annotated as inline comments in the code. The memory is byte-addressable.
// C-code
int a[10], b[10], i;
// int is 32-bit
for (i=0; i<10; i++)
a[i] = b[i] * 8;
; assembly-code (; indicates comments)
;r1–r5 are 32-bit integer registers
;initialize r1=0, r2=10
; r3, r4 with base address of a, b
L01: jeq r1, r2, end;if(r1==r2) goto end
L02: lw r5, 0(r4);r5 <- Memory[r4+0]
L03: shl r5, r5, U1;r5 <- r5 << U1
L04: sw r5, 0(r3);Memory[r3+0] <- r5
L05: add r3, r3, U2;r3 <- r3+U2
L06: add r4, r4, U3;r4 <- r4+U3
L07: add r1, r1, 1
L08: jmp U4;goto U4
L09: end
Which one of the following options is the CORRECT replacement for operands in the position (U1, U2, U3, U4) in the above assembly code?
- (8, 4, 1, L02)
- (3, 4, 4, L01)
- (8, 1, 1, L02)
- (3, 1, 1, L01)
Correct answer: (3, 4, 4, L01)
Solution
The correct option (3, 4, 4, L01) is right because the left shift operation in U1 must shift the value by 3 bits to multiply by 8 (2³), U2 should increment the address of array 'a' by 4 bytes (size of an int), and U3 should increment the address of array 'b' by 4 bytes as well. The jump back to L01 ensures the loop continues until the condition is met.
Related GATE Technical questions
- Which one of the following sequences when stored in an array at locations A[1],..., A[10] forms a max-heap?
- Let SLLdel be a function that deletes a node in a singly-linked list given a pointer to the node and a pointer to the head of the list. Similarly, let DLLdel be another function that deletes a node in a doubly-linked list given a pointer to the node and a pointer to the head of the list. Let n denote the number of nodes in each of the linked lists. Which one of the following choices is TRUE about the worst-case time complexity of SLLdel and DLLdel?
- Consider the Deterministic Finite-state Automaton (DFA) A shown below. The DFA runs on the alphabet {0,1}, and has the set of states {s,p,q,r}, with s being the start state and p being the only final state.
Which one of the following regular expressions correctly describes the language accepted by A?
- Which one of the options given below refers to the degree (or arity) of a relation in relational database systems?
- Suppose two hosts are connected by a point-to-point link and they are configured to use Stop-and-Wait protocol for reliable data transfer. Identify in which one of the following scenarios, the utilization of the link is the lowest.
- An algorithm has to store several keys generated by an adversary in a hash table. The adversary is malicious who tries to maximize the number of collisions. Let k be the number of keys, m be the number of slots in the hash table, and k > m.
Which one of the following is the best hashing strategy to counteract the adversary?
⚔️ Practice GATE Technical free + battle 1v1 →