Mnemonics

SRA

Rotate and Shift Group
Expansion:
Shift Rigth Arithmetic
Usage:
sra {r}

I don't think I've understood this correctly, marked for revision

The Shift Right Arithmetic will shift bits of a register or memory location to the right by one position. The most significant bit is preserved while the least significant bit is moved to the carry flag.

Z80.CPU instructions
Instruction Description Opcode
SRA A Shift bits in A register CB2F
SRA B Shift bits in B register CB28
SRA C Shift bits in C register CB29
SRA D Shift bits in D register CB2A
SRA E Shift bits in E register CB2B
SRA H Shift bits in H register CB2C
SRA L Shift bits in L register CB2D
SRA (HL) Shift bits at memory address HL register CB2E
SRA (IX+displacement) Shift bits in (IX + displacement) register DDCB {??}26
SRA (IY+displacement) Shift bits in (IY + displacement) register FDCB {??}26

Example

ld a, %11001010 ; load the binary value 11001010 into register A sra a ; shift the bits of A to the right ; result is A = %11100101 (arithmetic shift right) ; (C)arry flag = 0 (the bit that was shifted out)

Differences between SRA and SRL

SRA (this page)
SRL
  • Shifts all the bits in the specified register or memory location to the right by one position.
  • Most Significant Bit (MSB): The MSB (bit 7) is preserved (it remains unchanged).
  • Least Significant Bit (LSB): The LSB (bit 0) is shifted into the carry flag.
  • Useful for preserving the sign bit in signed binary numbers, effectively performing an arithmetic division by 2 while maintaining the sign of the number.
  • Shifts all the bits in the specified register or memory location to the right by one position.
  • SRL: Most Significant Bit (MSB): The MSB (bit 7) is cleared (set to 0).
  • Least Significant Bit (LSB): The LSB (bit 0) is shifted into the carry flag.
  • Useful for unsigned binary numbers, performing a logical division by 2.

See also