Regarding the x86 assembly of the program, in the program, the ‘JZ’ or ‘JNZ’ program will jump directly and end

Viewed 50

We know that JZ is used to determine the value of the ZF flag. The value of the ZF flag can only be 1 or 0. A jump occurs when using JZ or JNZ, which is unreasonable.

The program is compiled on x86, and the chip used is 8255. The function of the program is to use port b to read the state of the switch, and then output it to port A, where port A is connected to a small light bulb, and the light bulb is used to reflect the state of the switch. There are only two switches connected to port B. Kind of state.

The schematic diagram of the code and circuit is included below enter image description here

    CODES SEGMENT
    ASSUME CS:CODES
    
START:
     
      mov al,10000010b  ; 设置为控制字,A口方式0输出,B口方式0输入
      mov dx,41bh;41bh为控制寄存器的地址
      out dx,al;将控制字送入到控制寄存器中,完成芯片的初始化操作
L1:   mov dx,419h;419h为B口的地址
      in al,dx;从B口读入开关的状态
       
    
       
      
      
      mov dx,418h;418h为A口的地址
      out dx,al;将从B口读入的数据,输出到A口,控制灯的亮灭
       cmp al,0H
     
      JZ AB
      cmp al,0FFH
      JZ AB
      
      
      jmp  L1
         
      AB:MOV AH,4CH
      INT 21H
CODES ENDS
    END START
1 Answers
      ...
L1:   mov  dx, 0419h
      in   al, dx
      mov  dx, 0418h
      out  dx, al
      cmp  al, 0H
      JZ   AB          ; jumps if AL=0
      cmp  al, 0FFH
      JZ   AB          ; jumps if AL=255
      jmp  L1
AB:   MOV  AH, 4CH
      INT  21H

If the byte read at port 0419h is either 0 or 255, you exit the program immediately.
If that byte is [1,254], you stay in the L1 loop.

Since port b (0419h) contains the state of a switch, then perhaps 0 and 255 are the only values that can be read from the port?

Tip: Instead of writing cmp al, 0FFH JZ AB, you should use the je mnemonic that better expresses that this is comparing for equality:

  cmp  al, 0H
  je   AB          ; jumps if AL is equal to 0
  cmp  al, 0FFH
  je   AB          ; jumps if AL is equal to 255

You can use jz after a test instruction.

Related