User: alciro    User
 Original    Translate to:  Deutsch  English  Français  中文  
 

Microcontroladores 8051

4.2. Arithmetic instructions

Arithmetic instructions microcontroller 8051.

Arithmetic instructions of these microcontrollers are very limited, can add, subtract, increment, decrement and exceptionally has been integrated product and division of whole numbers.

ADD A, byte. Sum of 8 bits. Add contents of the accumulator with a byte with the address indicated, the result is in the tank.

MOV A,#3 ; A<-3 Mueve al Acumulador el dato inmediato 3
MOV R0,#2 ; A<-2 Mueve al registro 0 el dato inmediato 2
ADD A,R0 ; A<-(A)+(R0) Se suma el Acumulador con el Registro 0, el resultado queda en el Acumulador

ADDC A, byte. Addition with Carry. The sum amounts to Carry allows integer greater than 8 bits.

Example: Add two 16-bit integer variables that are the memory locations 30H and 32H. The result should be a third variable in position 34.

MOV A,30H ; A<-(30H) Mueve el contenido de 30H al Acumulador, parte baja de Variable 1
ADD A,32H ; A<-(A)+(32H) Suma el Acumulador con la posición 32H, parte baja de la Variable 2
MOV 34H,A ; 34H<-(A) Mueve el Acumulador a la posición 34H, el resultado a parte baja de la Variable 3
MOV A,31H ; A<-(31H) Mueve el contenido de 31H al Acumulador, parte alta de Variable 1
ADDC A,33H ; A<-(A)+(32H) Suma el Acumulador y el Carry con la posición 33H, parte alta de la Variable 2
MOV 35H,A ; 35H<-(A) Mueve el Acumulador a la posición 35H, el resultado a parte alta de la Variable 3

The following figure shows an outline of the contents of memory to perform the addition of two integers of 16 bits. It is assumed that the data of the sum (35FEH +00003 H) have been previously established and are being studied in this example.

Sum 16-bit integers in Assembly

SUBBED A byte. Subtract with Carry. Subtract the contents of a byte accumulator with the address indicated, the result is in the tank.

MOV A,#5 ; A<-5 Mueve al Acumulador el dato inmediato 5
CLR C ; C<-0 Pone a 0 el carry, por si en operaciones anteriores ha sido afectado, para que no interfiera en la resta
SUBB A,#03H ; A<-(A)-3 Se resta al Acumulador el dato inmediato 3, el resultado queda en el Acumulador

INC byte. Increase. Unit increases the contents of a byte (Acc, register, memory), with the address indicated.

MOV R0,#30H ; R0<-30H Mueve al registro 0 el dato inmediato 30H
INC @R0 ; ((R0))<-((R0))+1 Incrementa el contenido de la posición de memoria que indica R0

DEC byte. Decrease. Decrease of one unit the contents of a byte (Acc, register, memory), with the address indicated.

DEC R1 ; (R1)<-(R1)-1 Decrementa el contenido de R1

DA A. Adjust decimal accumulator. This instruction performs the setting in BCD format (0-9) nibbles of the accumulator (b0-b3 and least significant bits b4-b7 bits) the result of the sum with the ADD or ADDC instruction. This instruction is used when working with digit 7-segment BCD is necessary to work.

MUL AB. Multiplication of 8 bits. Performs a multiplication of integers of 8 bits unsigned values contained in the register A and B. The result is an integer of 16 bits, leaving the least significant part in the accumulator and the most significant in the register B.

DIV AB. Division 8-bit integer. Performs integer division 8-bit unsigned accumulator between the registry B. The accumulator is the result (quotient), while the remainder of integer division is in the register B.

Loading
copyright © 2007-2024  www.alciro.org  All rights reserved.         
Share |