Assembly Language for x86 Processors --- 4.2 课后习题答案

4.2 Addition and Subtraction

1 Is it possible to set the Overflow flag if you add a positive integer to a negative integer?(如果将正整数加到负整数,是否可以设置溢出标志?)

答 :No

2 Will the Overflow flag be set if you add a negative integer to a negative integer and produce a positive result?(如果将负整数加到负整数并产生正结果,是否会设置溢出标志?)

答 :Yes

3 Is it possible for the NEG instruction to set the Overflow flag?(NEG指令是否可以设置溢出标志?)

答 :Yes

4 Is it possible for both the Sign and Zero flags to be set at the same time?(是否可以同时设置符号和零标志?)

答 :No

5 Use the following data:
.data
val1 BYTE 10h
val2 WORD 8000h
val3 DWORD 0FFFFh
val4 WORD 7FFFh

a. Write an instruction that subtracts val3 from EAX.
b. Write an instruction that increments val2.
c. Write instructions that subtract val4 from val2.
d. If val2 is incremented by 1 using the ADD instruction, what will be the values of the Carry and Sign flags?
e. If val4 is incremented by 1 using the ADD instruction, what will be the values of the Overflow and Sign flags?

答 :
a. sub eax,val3

b. inc val2

c. mov ax,val4
sub val2,ax

d. CF = 0
SF = 1

e. OF = 1
SF = 1

6 Implement the following expression in assembly language: AX = (-val2 + BX) - val4.

答 :
mov ax,val2
neg ax
add ax,bx
sub ax,val4.

7 Write a sequence of two instructions that set both the Carry and Overflow flags at the same time.(编写两条指令的序列,同时设置进位和溢出标志。)

答 :
mov al,80h
add al,80h

8 Where indicated, write down the values of the Carry, Sign, Zero, and Overflow flags after each instruction has executed:

mov ax,7FF0h
add al,10h
; a. CF = SF = ZF = OF =

add ah,1
; b. CF = SF = ZF = OF =

add ax,2
; c. CF = SF = ZF = OF =

答 :
a. CF = 1 SF = 0 ZF = 1 OF = 0
b. CF = 0 SF = 1 ZF = 0 OF = 1
c. CF = 0 SF = 1 ZF = 0 OF = 0

猜你喜欢

转载自blog.csdn.net/weixin_43574277/article/details/105427729