You are on page 1of 61

Stack Instructions

PUSH
POP

PUSH

Operation:PUSH
Function:Push Value
Onto Stack
Syntax:PUSH
Description: PUSH
"pushes" the value of the
specified iram addr onto
the stack.
PUSH first increments
the value of the Stack
Pointer by 1, then takes
the value stored in iram
addr and stores it in
Internal RAM at the
location pointed to by
the incremented Stack
Pointer.

POP

Operation:POP
Function:Pop Value From
Stack
Syntax:POP
Description: POP "pops"
the last value placed on
the stack into the iram
addr specified.
In other words, POP will
load iram addr with the
value of the Internal
RAM address pointed to
by the current Stack
Pointer.
The stack pointer is then
decremented by 1.

PUSH

Implemented as intrinsic/inline
function.
The _push_ routine inserts a
PUSH instruction into the program
saving the contents of the Special
Function Register sfr on the stack.

PUSH
#include <intrins.h>
sfr value = 0xFF;
void main()
{
value = 1;
_push_(value);
}

POP

Implemented as intrinsic/inline
function.
The _pop_ routine inserts a POP
instruction into the program saving
the contents of the Special
Function Register sfr on the stack.

POP
#include <intrins.h>
sfr value = 0xFF;
void main()
{
value = 1;
_push_(value);
value = 0;
_pop_(value);
}

Unconditional Jumps

JMP

Operation:JMP
Function:Jump to
Data Pointer +
Accumulator
Syntax:JMP @A+DPTR
Description: JMP
jumps unconditionally
to the address
represented by the
sum of the value of
DPTR and the value of
the Accumulator.

SJMP

Operation:SJMP
Function:Short Jump
Syntax:SJMP reladdr
Description: SJMP
jumps unconditionally
to the address
specified reladdr.
Reladdr must be
within -128 or +127
bytes of the
instruction that
follows the SJMP
instruction.

AJMP

Operation:AJMP
Function:Absolut
e Jump Within 2K
Block
Syntax:AJMP
code address

LJMP

Operation:LJMP
Function:Long
Jump
Syntax:LJMP
code addr

ACALL

Operation:ACALL
Function:Absolute Call
Within 2K Block
Syntax:ACALL code
address
Description: ACALL
unconditionally calls a
subroutine at the indicated
code address.
ACALL pushes the address
of the instruction that
follows ACALL onto the
stack, least-significant-byte
first, most-significant-byte
second.

LCALL

Operation:LJMP
Function:Long Jump
Syntax:LJMP code
addr
Description: LJMP
jumps
unconditionally to
the specified code
addr.

RET

Operation:RET
Function:Return From
Subroutine
Syntax:RET
Description: RET is used to
return from a subroutine
previously called by LCALL
or ACALL.
Program execution continues
at the address that is
calculated by popping the
topmost 2 bytes off the
stack.
The most-significant-byte is
popped off the stack first,
followed by the leastsignificant-byte.

RETI

Operation:RETI
Function:Return From Interrupt
Syntax:RETI
Description: RETI is used to
return from an interrupt service
routine.
RETI first enables interrupts of
equal and lower priorities to the
interrupt that is terminating.
Program execution continues at
the address that is calculated
by popping the topmost 2 bytes
off the stack.
The most-significant-byte is
popped off the stack first,
followed by the leastsignificant-byte.

General Instructions

MOV

Operation:MOV
Function:Move Memory
Syntax:MOV
operand1,operand2
Description: MOV
copies the value of
operand2 into operand1.
The value of operand2 is
not affected.
Both operand1 and
operand2 must be in
Internal RAM.

MOVC

Operation:MOVC
Function:Move
Code Byte to
Accumulator
Syntax:MOVC
A,@A+register
Description: MOVC
moves a byte from
Code Memory into
the Accumulator.

MOVX

Operation:MOVX
Function:Move Data
To/From External
Memory (XRAM)
Syntax:MOVX
operand1,operand2
Description: MOVX
moves a byte to or
from External Memory
into or from the
Accumulator.

NOP

Operation:NOP
Function:None,
waste time
Syntax:No Operation
Description: NOP, as
it's name suggests,
causes No Operation
to take place for one
machine cycle.
NOP is generally used
only for timing
purposes.

XCH

Operation:XCH
Function:Exchange
Bytes
Syntax:XCH
A,register
Description:
Exchanges the value
of the Accumulator
with the value
contained in register.

Rotate Instructions

RR

Operation:RR
Function:Rotate
Accumulator Right
Syntax:RR A
Description: Shifts
the bits of the
Accumulator to the
right.
The right-most bit (bit
0) of the Accumulator
is loaded into bit 7.

RRC

Operation:RRC
Function:Rotate
Accumulator Right
Through Carry
Syntax:RRC A
Description: Shifts the
bits of the Accumulator to
the right.
The right-most bit (bit 0)
of the Accumulator is
loaded into the Carry
Flag, and the original
Carry Flag is loaded into
bit 7.

RL

Operation:RL
Function:Rotate
Accumulator Left
Syntax:RL A
Description: Shifts
the bits of the
Accumulator to the
left.
The left-most bit (bit 7)
of the Accumulator is
loaded into bit 0.

RLC

Operation:RLC
Function:Rotate
Accumulator Left
Through Carry
Syntax:RLC A
Description: Shifts the
bits of the Accumulator
to the left.
The left-most bit (bit 7) of
the Accumulator is
loaded into the Carry
Flag, and the original
Carry Flag is loaded into
bit 0 of the Accumulator.

ANL

Operation:ANL
Function:Bitwise AND
Syntax:ANL operand1,
operand2
Description: ANL does a
bitwise "AND" operation
between operand1 and
operand2, leaving the
resulting value in
operand1.
The value of operand2 is
not affected.

ORL

Operation:ORL
Function:Bitwise OR
Syntax:ORL
operand1,operand2
Description: ORL does a
bitwise "OR" operation
between operand1 and
operand2, leaving the
resulting value in
operand1.
The value of operand2 is
not affected.

XRL

Operation:XRLFuncti
on:Bitwise Exclusive
ORSyntax:XRL
operand1,operand2
Description: XRL
does a bitwise
"EXCLUSIVE OR"
operation between
operand1 and
operand2, leaving the
resulting value in
operand1.
The value of operand2
is not affected.

CPL

Operation:CPL
Function:Comple
ment Register
Syntax:CPL
operand
Description: CPL
complements
operand, leaving
the result in
operand.

SWAP

Operation:SWAP
Function:Swap
Accumulator Nibbles
Syntax:SWAP A
Description: SWAP
swaps bits 0-3 of the
Accumulator with bits
4-7 of the
Accumulator.
This instruction is
identical to executing
"RR A" or "RL A" four
times.

Arithmetic Instructions

ADD, ADDC

Operation:ADD, ADDC
Function:Add Accumulator, Add Accumulator With
Carry
Syntax:
ADD A,operand
ADDC A,operand
Description: ADD and ADDC both add the value
operand to the value of the Accumulator, leaving
the resulting value in the Accumulator.
The value operand is not affected. ADD and ADDC
function identically except that ADDC adds the
value of operand as well as the value of the Carry
flag whereas ADD does not add the Carry flag to
the result.

16 Bit Addition

Let's consider adding the following two


decimal values: 6724 + 8923.
The answer is, of course, 15647.
Convert the two values you wish to add
to hexadecimal.
In this case, that is equivalent to the
following hexadecimal addition: 1A44 +
22DB.
The completed answer is 3D1F

16 Bit Addition

16 Bit Addition

Since we're adding 16-bit values, each


value requires two 8-bit registers.
The first value to add will be held in R6
and R7 (the high byte in R6 and the low
byte in R7) while the second value to
add will be held in R4 and R5 (the high
byte in R4 and the low byte in R5).
We will leave our answer in R1, R2, and
R3.

16 Bit Addition
Following are the steps

Add the low bytes R7 and R5, leave


the answer in R3.
Add the high bytes R6 and R4,
adding any carry from step 1, and
leave the answer in R2.
Put any carry from step 2 in the final
byte, R1.

16 Bit Addition

Step 1: Add the low bytes R7 and


R5, leave the answer in R3.

MOV A,R7 ;Move the low-byte


into the accumulator
ADD A,R5 ;Add the second lowbyte to the accumulator
MOV R3,A ;Move the answer to
the low-byte of the result

16 Bit Addition

Step 2: Add the R6 and R4, add


carry, leave the answer in R2.

MOV A,R6 ;Move the high-byte into


the accumulator
ADDC A,R4 ;Add the second highbyte to the accumulator, plus carry.
MOV R2,A ;Move the answer to the
high-byte of the result

16 Bit Addition

Step 3: Put any carry from step 2


in the final byte, R1.

MOV A,#00h ;By default, the


highest byte will be zero.
ADDC A,#00h ;Add zero, plus
carry from step 2.
MOV R1,A ;Move the answer to
the highest byte of the result

SUBB

Operation:SUBB
Function:Subtract from
Accumulator With
Borrow
Syntax:SUBB A,operand
Description: SUBB
subtract the value of
operand from the value
of the Accumulator,
leaving the resulting
value in the
Accumulator. The value
operand is not affected.

MUL

Operation:MUL
Function:Multiply
Accumulator by B
Syntax:MUL AB
Description: Multiples
the unsigned value of
the Accumulator by the
unsigned value of the
"B" register.
The least significant
byte of the result is
placed in the
Accumulator and the
most-significant-byte is
placed in the "B"
register.

DIV

Operation:DIV
Function:Divide
Accumulator by B
Syntax:DIV AB
Description: Divides
the unsigned value of
the Accumulator by
the unsigned value of
the "B" register.
The resulting quotient
is placed in the
Accumulator and the
remainder is placed in
the "B" register.

INC

Operation:INC
Function:Increment
Register
Syntax:INC register
Description: INC
increments the
value of register by
1.
If the initial value of
register is 255 (0xFF
Hex), incrementing
the value will cause
it to reset to 0.

DEC

Operation:DEC
Function:Decrement
Register
Syntax:DEC register
Description: DEC
decrements the value
of register by 1.
If the initial value of
register is 0,
decrementing the
value will cause it to
reset to 255 (0xFF
Hex).

DA

Operation:DA
Function:Decim
al Adjust
Accumulator
Syntax:DA A

Bit Level and Other


instructions

SETB

Operation:SETB
Function:Set Bit
Syntax:SETB bit
addr
Description:
Sets the
specified bit.

CLR

Operation:CLR
Function:Clear Register
Syntax:CLR register
Description: CLR clears
(sets to 0) all the bit(s)
of the indicated register.
If the register is a bit
(including the carry bit),
only the specified bit is
affected.
Clearing the
Accumulator sets the
Accumulator's value to
0.

NOP

Operation:NOP
Function:None,
waste time
Syntax:No
Operation
Description: NOP, as
it's name suggests,
causes No Operation
to take place for one
machine cycle.
NOP is generally
used only for timing
purposes.

C Data types

Memory Types

Memory Types

Pointer Types

Generic Pointers.
Memory Specific Pointers.

Pointer Types

Generic pointers are declared like standard C


pointers.
For example:
char *s; /* string ptr */
int *numptr; /* int ptr */
long *state; /* Texas */
Generic pointers are always stored using three
bytes. The first byte is the memory type, the
second is the high-order byte of the offset, and
the third is the low-order byte of the offset.

Pointer Types

Memory-specific pointers always include a


memory type specification in the pointer
declaration and always refer to a specific
memory area.
For example:
char data *str; /* ptr to string in data */
int xdata *numtab; /* ptr to int(s) in xdata
*/
long code *powtab; /* ptr to long(s) in
code */

You might also like