Difference between revisions of "PM Opc SAR"

From SublabWiki
Jump to: navigation, search
(SAR Instruction)
 
(SAR = Shift Arithmetic Right)
 
(One intermediate revision by one other user not shown)
Line 14: Line 14:
 
|12
 
|12
 
|-
 
|-
|CE 8A
+
|CE 8A nn
 
|SAR [N+#nn]
 
|SAR [N+#nn]
 
|20
 
|20
Line 55: Line 55:
  
 
  ; A = 0x04 (4)
 
  ; A = 0x04 (4)
  SAR A
+
  '''SAR A'''
 
  ; A = 0x02 (2)
 
  ; A = 0x02 (2)
 
  ; F = (Zero=0):(Carry=0):(Overflow=0):(Sign=0)
 
  ; F = (Zero=0):(Carry=0):(Overflow=0):(Sign=0)
  
 
  ; A = 0xFD (-4)
 
  ; A = 0xFD (-4)
  SAR A
+
  '''SAR A'''
 
  ; A = 0xFE (-2)
 
  ; A = 0xFE (-2)
 
  ; F = (Zero=0):(Carry=0):(Overflow=0):(Sign=1)
 
  ; F = (Zero=0):(Carry=0):(Overflow=0):(Sign=1)
  
 
  ; B = 0x45 (69)
 
  ; B = 0x45 (69)
  SAR B
+
  '''SAR B'''
 
  ; B = 0x22 (34)
 
  ; B = 0x22 (34)
 
  ; F = (Zero=0):(Carry=1):(Overflow=0):(Sign=0)
 
  ; F = (Zero=0):(Carry=1):(Overflow=0):(Sign=0)
  
 
  ; B = 0x84 (-124)
 
  ; B = 0x84 (-124)
  SAR B
+
  '''SAR B'''
 
  ; B = 0xC2 (-62)
 
  ; B = 0xC2 (-62)
 
  ; F = (Zero=0):(Carry=0):(Overflow=0):(Sign=1)
 
  ; F = (Zero=0):(Carry=0):(Overflow=0):(Sign=1)
  
 
  ; [HL] = 0x01 (1)
 
  ; [HL] = 0x01 (1)
  SAR [HL]
+
  '''SAR [HL]'''
 
  ; [HL] = 0x00 (0)
 
  ; [HL] = 0x00 (0)
 
  ; F = (Zero=1):(Carry=1):(Overflow=0):(Sign=0)
 
  ; F = (Zero=1):(Carry=1):(Overflow=0):(Sign=0)
  
 
[[PM_InstructionList|'''« Back to Instruction set''']]
 
[[PM_InstructionList|'''« Back to Instruction set''']]

Latest revision as of 12:51, 27 March 2010

SAR = Shift Arithmetic Right

Hex Mnemonic Cycles
CE 88 SAR A 12
CE 89 SAR B 12
CE 8A nn SAR [N+#nn] 20
CE 8B SAR [HL] 16

Execute

A       = Register A
B       = Register B
[N+#nn] = Memory: (I shl 16) or (N shl 8) or #nn
[HL]    = Memory: (I shl 16) or HL
; SAR Ds
;
; Ds = Source/Destination

Ds = (Ds AND 0x80) OR (Ds SHR 1)

Description

"8-Bits Destination" bits are arithmetically shifted right by 1.

NOTE: This instruction can be used as an signed integer division by 2.

Conditions

Zero: Set when result is 0

Carry: Set when the old bit 0 was 1

Overflow: Always Reset (there's never a overflow)

Sign: Set when bit 7 of the result is 1

Examples

; A = 0x04 (4)
SAR A
; A = 0x02 (2)
; F = (Zero=0):(Carry=0):(Overflow=0):(Sign=0)
; A = 0xFD (-4)
SAR A
; A = 0xFE (-2)
; F = (Zero=0):(Carry=0):(Overflow=0):(Sign=1)
; B = 0x45 (69)
SAR B
; B = 0x22 (34)
; F = (Zero=0):(Carry=1):(Overflow=0):(Sign=0)
; B = 0x84 (-124)
SAR B
; B = 0xC2 (-62)
; F = (Zero=0):(Carry=0):(Overflow=0):(Sign=1)
; [HL] = 0x01 (1)
SAR [HL]
; [HL] = 0x00 (0)
; F = (Zero=1):(Carry=1):(Overflow=0):(Sign=0)

« Back to Instruction set