< http-equiv="Content-" content="text/; charset=utf-8">< name="ProgId" content="Word.">< name="Generator" content="Microsoft Word 12">< name="Originator" content="Microsoft Word 12"><link rel="File-List" href="file:///C:%5CDOCUME%7E1%5C2DBD%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml" target="_blank"><link rel="themeData" href="file:///C:%5CDOCUME%7E1%5C2DBD%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx" target="_blank"><link rel="colorSchemeMapping" href="file:///C:%5CDOCUME%7E1%5C2DBD%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml" target="_blank">< style>
- Consider the following 80X86
code segment.
2. section .data
3.
4. mov eax, 0
- l: shr ebx, 1
6. adc eax, 0
7. add
ebx, 0
8. jnz
l
We wish to write this code without
using any form of LOOP, and with no conditional jumps (we can use other forms
of JMP, however). Write a code segment that provides the same results for eax
(but may use or destroy other registers). You may NOT "unfold" the
above loop!
2.
Write
80X86 instructions to get a value of 1 in the ax register on an 80X86:
- List 5 different ways to do this with ONE instruction.
- List 1 way to do this with 2 instructions, each
different from all the instructions used in part 1.
- List the SHORTEST POSSIBLE CODE for adding 5 to y,
subtracting 2 from x, and adding 1 to z, which are defined as follows
(consecutive locations):
4. x
db 1
5. z
dw 330
6. y
db 7
If we know that subtracting 2 from x
and adding 1 to z cause no overflow, is there a shorter way to do that? How? Do
this: a) For an 80X86 machine, 2) For Motorola 68000, which is a big-endian
machine (assume that it has an instruction: ADDI.S #num, var that adds a number
num to a location in memory at address var. S is the operand size, one of: B
(byte), W (16 bit word), L (32 bit longword).
4.
Consider
the following 80X86 code segment. Assume that when the code is run, CX is
non-zero.
5. MOV
AX, 0
6. L: ADD
AX, BX
7. ADC DX, 0
8. LOOP
L
- What is the result of running the code?
- Re-write the above code segment for better efficiency.
- Consider the following code for Motorola 68000
(comments state what each instruction does, according to the 68000
instruction manual (no, we did not teach you that machine, you should
learn the relevant details on your own from the exercise). Note that the
68000 has 32-bit registers D0-D7 and A0-A7, where A7 is also the STACK
POINTER.
10.
F: MOVE.L D0, -(A7) ; D0 to memory - predecrement mode
11. SUBQ.L
#1, D0 ; Subtract immediate
- long (32 bit) operand
12. BMI
N ; Branch (jump) if
result was negative
13. JSR
F ; CALL subroutine F
(push PC then jump to F)
14. SUB.L
(A7)+, D2 ; Signed subtract
memory (postincrement)
15. ; with D2, result in
D2
16. RTS ; Return from
procedure/subroutine
17.
N: MOVE.L (A7)+, D0 ; Move memory to D0 - postincrement mode
18. MOVEQ.L
#0, D2 ; Move immediate to
D2
19. RTS
What happens if we execute an
instruction JSR F, with D0=0? D0=1? Other values of D0 (call that value k)?