Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

x86 16 - Storing Flag Values in Variables in 8086 - Assembly Language

I wanted to ask that is there any explicit and easy way to store the values of flags such as(carry flag, auxiliary flag, parity flag, zero flag, overflow flag, signed flag etc.) in variables such as;

.data
 carry_flag db 0
 auxiliary_flag db 0
 zero_flag db 0

I have researched a lot but couldn't find a way to "store" values of flags in a variable in 8086 processor. We can surely view the flags using any debugger such as AFD Debugger but what if we want to store them on run-time and show them to the user at the end of the program.

Please suggest an easy way to store the values of all such flags from flag register into variables in 8086 Assembly Language - MASM.

Thank you in advance!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I wanted to ask that is there any explicit and easy way to store the values of flags in variables

The easiest way will use a loop. Next code snippets will store the 9 flags that are available on 8086 in byte-sized variables. If the flag is OFF you get 0, if the flag in ON you get 1.

Allowing 3 unused data bytes (simpler)

.data
  CF db 0
     db 0
  PF db 0
     db 0
  AF db 0
     db 0
  ZF db 0
  SF db 0
  TF db 0
  IF db 0
  DF db 0
  OF db 0

  ...

  pushf
  pop     dx
  mov     di, offset CF
  mov     cx, 12
  cld
More:
  shr     dx, 1
  mov     al, 0
  rcl     al, 1
  stosb
  dec     cx
  jnz     More

No unused data bytes (ideal for continuous displaying)

.data
  CF db 0
  PF db 0
  AF db 0
  ZF db 0
  SF db 0
  TF db 0
  IF db 0
  DF db 0
  OF db 0

  ...

  pushf
  pop     dx
  mov     di, offset CF
  mov     cx, 12
  mov     bx, 0FD5h     ; Mask of defined flags
  cld
More:
  shr     dx, 1
  mov     al, 0
  rcl     al, 1
  shr     bx, 1
  jnc     Skip          ; Bit does not correspond to a defined flag
  stosb
Skip:
  dec     cx
  jnz     More

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...