The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
44 views

Consider following assembly language program for a hypothetical processor with $32$ bit accumulator register.
Note that $\text{xchg}$ is a swap operation and $\text{arr}$ is an array.

$\text{arr}:[1,2,3,4]$
$\text{mov } \text{eax,arr}$
$\text{xchg eax},[\text{arr}+4]$
$\text{xchg eax},[\text{arr}+8]$
$\text{xchg eax},[\text{arr}+8]$
$\text{xchg eax},[\text{arr}+12]$
$\text{xchg arr, eax}$

What is the value of array $\text{arr}$ after the completion of above code?

  1. $4,3,2,1$
  2. $1,1,3,2$
  3. $1,1,2,3$
  4. $4,1,3,2$
asked in CO & Architecture by Boss (17.2k points)
edited by | 44 views

1 Answer

+1 vote
mov eax,arr: $\rightarrow$ eax=1, arr=[1,2,3,4]
xchg eax,[arr+4]: $\rightarrow$ eax=2, arr=[1,1,3,4]
xchg eax,[arr+8]: $\rightarrow$ eax=3, arr=[1,1,2,4]
xchg eax,[arr+8]: $\rightarrow$ eax=2, arr=[1,1,3,4]
xchg eax,[arr+12]: $\rightarrow$ eax=4, arr=[1,1,3,2]
xchg arr,eax: : $\rightarrow$ eax=1, arr=[4,1,3,2]
answered by Boss (17.2k points)
edited by
Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,117 questions
53,218 answers
184,619 comments
70,454 users