Programming using arithmetic, logical and bit manipulation instructions of 8051
Aim:
To write ALP for performing Arithmetic , Logical , Bit manipulation operations in 8051
Apparatus:
1. ADS-SDA-51-STA kit 2. Microprocessor Power Supply 3. RS 232 Cable 5. Adapter, Keyboard, Cables, Connecting Wires Etc...
Procedure:
For generating HEX file:
1. Check for Driver folder (if driver is in D drive) 2. Go to Command Prompt 3. Type d: and Press enter (if driver is in D drive) 4. Type cd Driver and Press enter 5. Type cd x8051 and Press enter 6. Edit filename.asm Enter 7. Now a window appears in which you need to write the program and save it . 8. Go to file→Exit. You will return to command prompt 9. To check errors and generate .obj file Type x8051 and Press enter in the command prompt. a. Select the option D and enter b. Select the option Y to generate cross-reference and enter c. Enter Input file name as: filename.asm d. Enter output filename as: filename.obj 10. Now the .obj file is generated and errors will be displayed 11. To link the file now type link and Press enter a. Enter input filename as: filename.obj b. To skip the entry of input, output and library files which are already c. added press enter 3 times d. Enter offset address as: 0000 e. Select the option H to generate .hex file 12. Hex file is generated and the length and memory address of hex file will be displayed. Now note down the starting and ending address.
To observe the output:
1. Connect the 8051 kit to the processor of desktop with Rs232 cable and power supply to the 8051 Kit. 2. Open the TALK icon which is on desktop now Talk window appears. 3. In that window go to options → Target Board → 8051 → ok. 4. Go to options → Connect. 5. Press E on kit keyboard to activate serial port of the kit. Now ‘SERIAL PORT’ displays on the kit and ‘ALS 8051 STA’ displays on talk window. 6. Go to file → Download Hexfile. Select the HEX file which is generated by following the path D drive →driver → X8051 → filename.hex. Now I appears on TALk window to indicate that file is downloaded. 7. Type G and Starting address of HEX file and press enter. 8. Now program gets executed and register status will be displayed. 9. To generate opcode Press Z starting address of hex file and enter.
1. Arithematic operations:
Program:
org 9000h ;addition without carry mov a, #06h mov b, #09h add a, b mov r0, a ;Substraction with carry mov a, #08h subbc a, #03h mov r1, a ;multiplication mov a, #03h mov b, #06h mul ab mov r2, a ;division mov a, #08h mov b, #03h div ab mov r3, a mov r4, b ;increment operation mov a, #03h inc a mov r5, a ;decrement operation mov r6, #07h dec r6 lcall 0003h end
2. Logical operations:
Program 1:
org 8000h mov r0, #0fh mov r1, #foh mov r2, #66h ; And operation mov a, #ffh anl a, r0 mov r3, a ; Or operation mov a, #ffh orl a, r1 mov r4, a ; Xor operation mov a, 03h mov a, #ffh xrl a, r2 mov r5, a lcall 0003h end
Program 2:
org 9000h ; clear register A mov a, #0fh clr a mov r0, a ; swap nibbles of register A mov a, #56h swap a mov r1, a ; Complement the bit of register A mov a, #66h cpl a mov r2, a ; Rotate the register contents towards right mov a, #63h rr a xrl a, r mov r3, a ; Rotate the register contents towards left mov a, #43h rl a xrl a, r mov r4, a lcall 0003h end
3. Bit manipulation operations:
Program:
org 9000h
mov a, #ffh
clr c
;clear the carry flag
anl c, acc.7
mov r0, a
setb c
;set the carry flag
mov a, #00h
orl c, acc.5
mov r1, a
mov a, #ffh
cpl acc, 3
mov r2, a
lcall 0003h
end
Result:
Arithmetic , Logical , Bit manipulation operations in 8051 were performed and opcode and register contents were noted.
-
UpdatedOct 25, 2014
-
Views21,352
You May Like
Programs for 16 bit arithmetic operations for 8086 (using various addressing modes)
Program for String manipulations for 8086
Program for sorting an array for 8086
Program for searching for a number or character in a string for 8086
Program for digital clock design using 8086.
Programming using arithmetic, logical and bit manipulation instructions of 8051