Download Tutorial-2_Computer Organization

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
TUTORIAL 2
COMPUTER ORGANIZATION
Question 1
Use the following variable definition for the remaining questions in this section:
.data
MyByte SBYTE -10,-20,-11,11
MyWord WORD 300h,400h,500h,600h
MyDWord DWORD 11300h, 12400h,12500h,11600h
a)
For the following statements, state whether or not the instruction is valid. Give comment to
describe the reason why the instruction become valid or invalid.
i)
ii)
iii)
iv)
b)
mov ax, MyByte
mov ax, MyWord
mov eax, MyDWord
movzx ax, MyWord
What will be the value of the destination operand after each of the following instructions
executes in sequence? Write appropriate comment to explain the operation executed by the
instruction.
mov ax, MyWord
___________________________________________________________________
mov ax,[MyWord + 2]
___________________________________________________________________
add ax, [MyWord + 2]
___________________________________________________________________
Question 2
a) Use the following data for the next several questions:
.data
Val1 WORD 8000h
Val2 WORD FFFFh
Val3 WORD 7FFFh
Val4 BYTE 11001001b
i.
Write an instruction that transfer value of Val2 to register EAX.
ii.
Write an instruction to decrement value of Val1.
iii.
Write the instruction to EXCHANGE val3 to val2.
1
Question 3
a)
For the following statements, state either the instructions are valid or invalid and
state the reasons:
i)
ii)
xchg var1,var2
xchg var1,bx
b)
State the values of the destination operand after the following instructions are
executed in sequence. State the comments to explain the operations executed by
the instructions as well.
.data
arrayW WORD 1000h,2000h,3000h
arrayD DWORD 1,2,3,4
.code
i)
ii)
iii)
mov ax,[arrayW+2]
mov ax,[arrayW+4]
mov eax,[arrayD+4]
Question 4
a)
Trace the error for the following assembly program. Rewrite and underline the correct
statement.
TITLE Add signed int, Version 2
(Addsigned.asm)
; This program adds and subtracts 32-bit integers
; and stores the sum in a variable.
; Last update: 30 dec 2007
val1
dword 100h
num1 sdword -10h
finalVal dword ?
main PROC
mov eax,val1
add eax,num1
mov finalVal,eax
; start with 10000h
; val1 add byte num1
; store the result (30000h)
exit
main ENDP
END main
(5 marks)
2
b)
Trace the output for EAX and EBX the following program.
INCLUDE Irvine32.inc
.data
val2 WORD 24h
val3 DWORD 11011b
val4 DWORD 8d
.code
main PROC
mov ax,val2
neg ax
movzx eax,ax
xchg eax,val3
mov ebx,val4
xchg ebx,val3
call DumpRegs
exit
;display the registers
main ENDP
END main
(5 marks)
Question 5
Write a complete program in assembly language that implements the following arithmetic
expression:
EAX = -val2 * 7 + val3
In comments next to each instruction, write the hexadecimal value of EAX. Insert a call
DumpRegs statement at the end of the program.
Use the following data definition in your program:
.data
val2 SDWORD -33500h
val3 DWORD 210h
3
Question 6
Write a complete program using MASM Assembly Language 32-bit integers with different
registers. Insert the call DumpRegs statement to display the registers and flags. Apply the
following arithmetic expression and data given.
answer = (-val2 + val3) * val1
Use the following data:
val1 = 334h
val2 = 0C1h
val3 = 427d
(15 marks)
4