Skip to contentSkip to conversation

x86: fix daa opcode for al register values higher than 0xf9

PATCH Applied Boris Figovsky 3 participants 3 messages Aug 30, 2011 – Sep 2, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: fix daa opcode for al register values higher than 0xf9

The second if statement should consider the original al register value, and not the new one.

---
 target-i386/op_helper.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
target-i386/op_helper.c +3 -3
index 1bbc3b5..1fc248f 100644
@@ -1970,20 +1970,20 @@ void helper_aas(void)
 
 void helper_daa(void)
 {
-    int al, af, cf;
+    int old_al, al, af, cf;
     int eflags;
 
     eflags = helper_cc_compute_all(CC_OP);
     cf = eflags & CC_C;
     af = eflags & CC_A;
-    al = EAX & 0xff;
+    old_al = al = EAX & 0xff;
 
     eflags = 0;
     if (((al & 0x0f) > 9 ) || af) {
         al = (al + 6) & 0xff;
         eflags |= CC_A;
     }
-    if ((al > 0x9f) || cf) {
+    if ((old_al > 0x99) || cf) {
         al = (al + 0x60) & 0xff;
         eflags |= CC_C;
     }
Signature · 1 line
1.7.0.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Boris Figovsky

The second if statement should consider the original al register value, and not the new one.

(It took me some time to convince myself that the line
CF <- old_CF or (Carry from AL <- AL + 6)
in the Intel architecture manual is actually redundant; the AMD docs are much clearer here...)

-- PMM