From C64-Wiki
Jump to navigationJump to search

ASL (short for "Arithmetic Shift Left") is the mnemonic for a machine language instruction which "shifts" the bits in either the accumulator or a specified address in RAM, one bit position towards the "left", or most significant, "end" of the byte. The bit previously held at the most significant position is "shifted out" of the byte, and into the carry flag, whereas the least significant bit, "left empty" by the shift operation, is "filled in" with a zero bit.

If the byte affected by the operation is taken as an unsigned 8-bit integer, the ASL operation effectively doubles the number, leaving a result of up to nine bits, the most significant of which is subsequently held in the carry flag. Doubling signed integers in this way requires programming efforts to keep the sign bit from mixing with the other bits, causing erratic sign-changes.

It is interesting to note that whereas ADC and SBC do not come in "flavours" which do not take an incoming carry or borrow, both ASL and its counterpart, LSR, are complemented by the instructions ROL and ROR, which "fills the vacant bit" with what was in the carry flag prior to the operation. Historically, ASL and LSR was implemented in the very first 65xx CPUs, whereas ROL and ROR was only added in CPUs manufactured after a certain date.

The following example shows how to left-shift, or double the value of, an integer spanning several bytes:

ASL Num    Shift least significant byte
ROL Num+1  Shift next-to-least-significant byte
ROL Num+2  Shift the byte after that
ROL Num+7  Shift most significant byte

Addressing modes[edit | edit source]

Opcode Addressing
in bytes
Number of
Dec Hex
10 0A Accumulator ASL A 1 2
14 0E Absolute ASL nnnn 3 6
30 1E Absolute,X ASL nnnn,X 3 7
6 06 Zeropage ASL nn 2 5
22 16 Zeropage,X ASL nn,X 2 6

ASL supports the five addressing modes shown in the table at right. In the assembler formats listed, nn represents a single-byte (8-bit) figure, and nnnn is a two-byte (16-bit) address.

CPU flags[edit | edit source]

ASL affects 3 of the CPU's status flags:

  • The negative status flag is set if the result is negative, i.e. has its most significant bit set.
  • The zero flag is set if the result is zero, or cleared if it is non-zero.
  • The carry flag is set or cleared depending on the result.