0% found this document useful (0 votes)
3 views

AssemblyProgramPractice

The document provides examples of assembly language programming for the 8051 microcontroller, including addition, subtraction, and various instructions. It explains the use of registers, data manipulation, and integrated development environments (IDEs) for programming. Additionally, it outlines specific values to configure ports and registers for input and output operations.

Uploaded by

rangerboy964
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

AssemblyProgramPractice

The document provides examples of assembly language programming for the 8051 microcontroller, including addition, subtraction, and various instructions. It explains the use of registers, data manipulation, and integrated development environments (IDEs) for programming. Additionally, it outlines specific values to configure ports and registers for input and output operations.

Uploaded by

rangerboy964
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Assembly Language Programming

Practice
https://www.eeemadeeasy.com/8051-microcontroller-instruction-set/#Subtraction
Examples
Addition of two numbers:
ORG 0000H
MOV A, # 05H 05 - 0000 0101
ADD A, # 02 H 02 - 0000 0010
END 07 0000 0111
0F 0000 1111
02 0000 0010
1 0001
Examples
Addition of two numbers:
ORG 0000H
MOV A, #0AH 0A - 0000 1010
ADD A, # 02h 02 - 0000 0010
END 0C - 0000 1100
Different Versions of MOV Instruction
Examples
Addition of two numbers:
ORG 0000H
MOV A, #0FFH FF - 1111 1111
ADD A, # 01H 01 - 0000 0001
END 100 - 0001 0000 0000

75H 0111 0101 3C 0011 1100 38 0011 1000


0A H 0000 1010 3B 0011 1011 2F 0010 1111
7F 0111 1111 77 0111 0111 67 0110 0111
What will be the contents of A after the
execution of following instructions?
ORG 0000H
MOV A, #75H
MOV R0, #0AH
L1: INC A
DJNZ R0,L1
END

ANS:7F
What will be the contents of A after the
execution of following instructions?
ORG 0000H
MOV R0, #30H
MOV 30H, #01H
MOV A, @R0
RL A
RL A
END

ANS:04
What value to be loaded in register PSW for
selecting Bank3
MOV PSW , #
What is the address of register R7?
ORG 0000H
CLR PSW.3
SETB PSW.4
MOV R7,A
END

ANS:R7 from Register Bank2


What will be the contents of A after the execution of
following instructions?
ORG 0000H
MOV A, #73H
XRL A, #73H
END

ANS:00
How many times will the loop be executed in the
following set of instructions?
ORG 0000H
MOV A, #55H A= 0101 0101

MOV R3, #10 R3= 0001 0000


NEXT:MOV R2, #70
UP: CPL A R2= 0111 0000

DJNZ R2, UP
DJNZ R3, NEXT
END

ANS:700
What will be the contents of A after the
execution of following instructions?
ORG 0000H
MOV A, #47H
MOV R0, #25H
ADD A, R0
DA A
END

ANS:72
What is the location value of R0 and the content at that place
after the following set of instructions are executed?
ORG 0000H
MOV R0, #56H
MOV A, #05
ADD A, R0
DA A
INC R0
MOV @R0, A
END

ANS:R0=57
What will be the contents of R0 and A after the
execution of following instructions?
ORG 0000H
MOV A, #32H
MOV R0, #56H
CJNE A, R0, L1
INC R0
L1: INC A
END

ANS:A= 33 & R0=36


What will be the contents of R0 and A after the execution
of following instructions?
ORG 0000H
MOV R0, #40H
MOV @R0, #72H
MOV A, #03H
ADD A, @R0
JNC L1
INC A
L1:INC R0
END

ANS:A=75H; R0=41H
What is the result in A, @R1 after the following set of
instructions are executed?

ORG 0000H
MOV A, #72H
MOV R1, #70H
MOV 70H, # 43H
XCHD A, @R1
END

ANS:A=73H; R1=42H
What is the value of the bits 0-3 of @R0 after the
following instructions are executed?

ORG 0000H
MOV @R0, #05H
MOV A, #21H
XCHD A, @R0
END

ANS:A=25H;R0=01
What is the value of the bits 0-3 of @R0 after the
following instructions are executed?

ORG 0000H
MOV @R0, #05H
MOV A, #21H
XCHD A, @R0
END

ANS:
What will be contents of DPTR after execution of
following instructions?
ORG 0000H
MOV DPTR, #5006H
MOV A, #4
MOVC A, @A + DPTR
END
ANS:
What will be contents of DPTR after execution of following
instructions?
ORG 0000H
MOV DPTR, #5006H
MOV A, #4
MOVC A, @A + DPTR
END
ANS: 5006H
What will be the contents of the registers R2 and R3
after the following instructions are executed?
ORG 0000H
MOV DPTR,#00FF H
MOV R2,DPL
MOV R3,DPH
END

ANS:
Which is equivalent instruction?
ORG 0000H
MOV A, #55H
RL A
RL A
RL A
RL A
END
ANS:
What will be the contents of A after the execution
of following instructions? Consider CY = 1 initially
ORG 0000H
CLR C
MOV A, #4CH
SUBB A, #6EH
END

ANS:DE in accumulator carry flag set


PUSH
MOV R6, #25H
MOV R1, #12H
MOV R4, #0F3H
PUSH 6
PUSH 1
PUSH 4 0A
0F3
09 12 12
08 25 25 25

SP=07 SP=08 SP=09 SP=0a


POP

POP 4
POP 1
POP 6 0A
0F3
09 12 12

08 25 25
25 25

SP=0A SP=09 SP=08


Multiplication Operation

The register A and B will be used for multiplication. No other registers


can be used for multiplication. The result of the multiplication may exceed
the 8-bit size. So the higher order byte is stored at register B, and lower
order byte will be in the Accumulator A after multiplication.
Find output of Program

MOV R0, #20H ;set source address 20H to R0


MOV R1, #30H ;set destination address 30H to R1

MOV A, @R0 ;take the first operand from source to register A


INC R0 ; Point to the next location
MOV B,@R0 ;take the second operand from source to register B

MUL AB ;Multiply A and B

MOV @R1, B ; Store higher order byte to 30H


INC R1 ; Increase R1 to point to the next location
MOV @R1, A ;Store lower order byte to 31H
HALT: SJMP HALT ; Stop the program
• Value to be loaded in PnMDOUT to make P0 as output port
P0MDOUT= 0XFFH

• Value to be loaded in PnMDIN to make P0 as Input digital port

P0MDIN= 0XFFH

• Value to be loaded in PnMDIN to make P0 as analog Input port

P0MDIN= 0X00H
What Is An Integrated Development
Environment (IDE)?
• Integrated development environments (IDE) are applications that facilitates
the development of other applications. Designed to encompass all
programming tasks in one application, one of the main benefits of an IDE is
that they offer a central interface with all the tools a developer needs,
including:
• Code editor: Designed for writing and editing source code, these editors are
distinguished from text editors because work to either simplify or enhance
the process of writing and editing of code for developers
• Compiler: Compilers transform source code that is written in a human
readable/writable language in a form that computers can execute.
• Debugger: Debuggers are used during testing and can help developers debug
their application programs.
• Build automation tools: These can help automate developer tasks that are
more common to save time.
Languages That Are Supported by IDE

• In some cases, IDEs are dedicated to a certain programming


language or to a set of languages, which creates a feature
set that aligns with the specifics of that language. For
example, Xcode for the Objective-C and Swift languages,
Cocoa and Cocoa Touch APIs.
• However, multiple-language IDEs, like Eclipse (C, C++, Python,
Perl, PHP, Java, Ruby and more), Komodo (Perl, Python, Tcl,
PHP, Ruby, Javascript and more) and NetBeans (Java,
JavaScript, PHP, Python, Ruby, C, C++ and more) do exist.
• Multi-Language IDE
• The multi-language IDEs – like Eclipse, Aptana, Komodo,
NetBeans, and Geany – support multiple programming
languages.
• Eclipse: Supports C, C++, Perl, Python, Ruby, PHP, Java and
others. It is a free and open source editor for many
development frameworks. Although it began as a Java
development environment, it has expanded through plugins.
This IDE is managed and directed by the Eclipse.org
Consortium.
Simplicity Studio and Keil µVision® IDE

• The Simplicity IDE is an Eclipse-based Integrated Development


Environment (IDE) enabling code editing, downloading, and
debugging for Wireless (including EM35xx), Wireless Geckos,
Wireless Modules, EFM32, EFM8, and 8051 devices

µVision® IDE
The µVision IDE combines project management, run-time environment,
build facilities, source code editing, and program debugging in a single
powerful environment. µVision is easy-to-use and accelerates your
embedded software development. µVision supports multiple screens and allows you to create
individual window layouts anywhere on the visual surface.

The µVision Debugger provides a single environment in which you may test, verify, and optimize
your application code. The debugger includes traditional features like simple and complex
breakpoints, watch windows, and execution control and provides full visibility to device
peripherals.
• Value to be loaded in P0MDOUT to make P0 as output port

• Value to be loaded in P4MDOUT to make P4 as output port

• Value to be loaded in P3MDOUT to make P3.3 as output port pin

• Value to be loaded in P0MDIN to make P0 as Input digital port

• Value to be loaded in P3MDIN to make P3 as digital Input port

• Value to be loaded in P0MDIN to make P0 as analog Input port

• Value to be loaded in P0MDIN to make P3.2 as analog input


Solution
• Value to be loaded in P0MDOUT to make P0 as output port
P0MDOUT= 0XFFH
• Value to be loaded in P4MDOUT to make P4 as output port
P4MDOUT= 0XFFH
• Value to be loaded in P3MDOUT to make P3.3 as output port pin
P3MDOUT= 0X08H
• Value to be loaded in P0MDIN to make P0 as Input digital port
P0MDIN= 0XFFH
• Value to be loaded in P3MDIN to make P3 as digital Input port
P3MDIN= 0XFFH
• Value to be loaded in P0MDIN to make P0 as analog Input port
P0MDIN= 0X00H
• Value to be loaded in P0MDIN to make P3.2 as analog input
P3MDIN= 0XFBH
XBR0 = 0x07

XBR1 = 0x43

P0SKIP = 0x0C

P1SKIP = 0x01

You might also like