2
votes

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!

1
PUSHF : Push FLAGS Register onto the StackMikeCAT
Can you please elaborate it by a code-snippet as it's really hard to understand from the link that you have provided. Like, how am I going to extract the values after pushing the register onto stack? Please provide a code snippet for any flag that you want. Thanks in advance!Hammad
Consult a manual about which flag is at which bit position. E.g. AF is bit #4 so you could pop ax; shr al, 4; and al, 1; mov [auxiliary_flag], alJester
We're shifting it to right using shr then isn't it going to be like: shr ah, 1; and then: and ah, 1 and so on.. Shouldn't we do work with ah? as it is on the higher side (means right)Hammad

1 Answers

2
votes

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