Compilation of learning - the thirteenth day

11.12 flag register indicates the Debug

Overflow flag OF overflow flag operand out of the machine represents the range that can be represented overflow overflows to 1. 
SF Sign In Flag symbol glyph recording operation result, when a negative result 1. 
the ZF Zero Flag ZERO In Flag calculation result is equal to 0 to 1 otherwise 0. 
when a carry CF2 carry flag into the flag the most significant bit is 1, otherwise 0. 
the AF auxiliary when the carry when the flag auxiliary flag operation, bit 3 generates a carry to bit 4 is 1, and 0 otherwise. 
parity flag PF parity flag bit operand arithmetic result is an even number as the number is 1, otherwise of 0. the 
the DF flag for direcion in flag sequence processing direction .DF = 1, so that after each operation is reduced SI and DI .DF = 0 is increased. 
the iF interrupt In flag interrupt flag iF = 1, the CPU allows a maskable interrupt, the interrupt disabled otherwise. 
TF trap In flag trap flag single operation for debugging

 

of

df

if

sf

zf

of

pf

cf

Flag is 1

ov

dn

No

of

zr

ac

on

cy

Flag to 0

nv

up

of

pl

nz

na

po

nc

 

 

One correspondence with the eight debug the right.

 

11.9 transition condition detection result of the comparison

I.e. determines whether to change the conditions in accordance with IP

For example jcxz, most conditional branch instruction, by detecting a flag register (register is affected cmp) result associated flag, to determine whether to modify IP.

Unsigned comparison: a detection zf, cf

Signed and comparison: detecting sf, of, zf

 

instruction meaning Related flag detection
it is Equal to the transfer zf=1
etc. It is not equal to the transfer zf=0
jb Lower than the transfer cf=1
JNB Not less than the transfer cf=0
and Higher than the transfer zf = 0 and cf = 0
jna No more than the transfer cf = 1 or zf = 1

 

 

Achieved if (ah) = (bh), then (ah) = (ah) + (ah), or (ah) = (ah) + (bh)

assume cs:code
code segment
start:
    cmp ah,bh
    je s
    add ah,bh
    jmp short ok
    
s:
    add ah,ah
    
ok:
    mov ax,4c00h
    int 21h
code ends
end start

 

je judgment is zf position, regardless of what command before, as long as zf = 1, then the transfer.

assume cs:code
code segment
start:
    mov ax,0
    add ax,0
    je s
    inc ax
s:    inc ax
    mov ax,4c00h
    int 21h
code ends
end start

 

Statistical programming data value of the number of bytes in paragraph 8, ax save the result.

assume cs:code
data segment
    db 8,11,81,8,6,63,55,8
data ends
code segment
start:
    mov ax,data
    mov ds,ax
    mov si,0
    mov cx,8
    mov ax,0
    
s:
    cmp byte ptr [si],8
    jne next    
    inc ax
next:
    inc si
    loop s
    
    mov ax,4c00h
    int 21h
code ends
end start

 

2.编程统计大于8的个数,用ax保存结果。

assume cs:code
data segment
    db 8,11,81,8,6,63,55,8
data ends
code segment
start:
    mov ax,data
    mov ds,ax
    mov si,0
    mov cx,8
    mov ax,0
    
s:
    cmp byte ptr [si],8
    ja ok
    jmp short next
ok:    
    inc ax
next:
    inc si
    loop s
    
    mov ax,4c00h
    int 21h
code ends
end start

 

3.统计小于8的个数,结果保存在ax

assume cs:code
data segment
    db 8,11,81,8,6,63,55,8
data ends
code segment
start:
    mov ax,data
    mov ds,ax
    mov si,0
    mov cx,8
    mov ax,0
    
s:
    cmp byte ptr [si],8
    jb ok
    jmp short next
ok:    
    inc ax
next:
    inc si
    loop s
    
    mov ax,4c00h
    int 21h
code ends
end start

 

检测点 11.3

(1)

jb s0

ja s0

(2)

jna s0

jnb s0

 

11.10 DF标志和串传送指令

 在串指令中,控制每次操作之后si,di的增减。

DF=1  每次操作之后,si,di递增

DF=0  每次操作之后,si,di递减

 

rep作用:根据cx,反复执行后面的串传送指令

rep movsb(repeat move string byte)

rep movsw(repeat mov string word)

 

对CF位进行操作

cld( Clear Director):将标志寄存器的df位清0

std(Set Director):将标志寄存器的df位设置为1

 

1.使用串传送指令,将data段中的第一个字符串复制到他后面的空间中

assume cs:code
data segment
    db 'Welcome to masm!'
data ends
code segment
start:
    mov ax,data
    mov ds,ax
    mov es,ax
    mov si,0
    mov di,10h
    mov cx,16
    cld
    rep movsb
    
    mov ax,4c00h
    int 21h
code ends
end start

 

2.利用串传送指令,将F000H段中最后16个字符复制到data段中

assume cs:code
data segment
    db 16 dup (0)
data ends
code segment
start:
    mov ax,data
    mov es,ax
    mov ax,0F000H
    mov ds,ax
    mov si,0ffffh
    mov di,15
    mov cx,16
    std
    rep movsb
    
    mov ax,4c00h
    int 21h
code ends
end start

也可以顺序存储

assume cs:code
data segment
    db 16 dup (0)
data ends
code segment
start:
    mov ax,data
    mov es,ax
    mov ax,0F000H
    mov ds,ax
    mov si,0fff0h
    mov di,0
    mov cx,16
    cld
    rep movsb
    
    mov ax,4c00h
    int 21h
code ends
end start

 

 

11.11 pushf和popf

pushf 将标志寄存器的值压入栈中

popf 将标志寄存器的值弹出栈中

检测点11.4

对flag寄存器操作

ax=45h

mov ax,0
push ax
popf;将标志寄存器置
mov ax,0fff0h
add ax,0010h
;ax实际结果为0,应得结果:-16+16=0
;flag寄存器值:0000 0000 0100 0101=69
pushf;将标志寄存器值入栈
pop ax;将标志寄存器值出栈给ax
and al,1100 0101b;0100 0101
and ah,0000 1000b;0000 0000
;所以ax=0000 0000 0100 0101=45h

 

Guess you like

Origin www.cnblogs.com/Mayfly-nymph/p/11204361.html