Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to write logic statement in assembly language

Status
Not open for further replies.

vead

Full Member level 5
Full Member level 5
Joined
Nov 27, 2011
Messages
285
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
india
Visit site
Activity points
3,815
I want to write assembly code for 8051

switch A is connected to P0.1
switch B is connected to P0.2
LED is connected to P1.0

IF one switch or both high then the LED is turn on otherwise turn off

switch A high then turn on LED
switch B high then turn on LED
both A B high then turn on LED
both A B low then turn off led
I want to write assembly program using OR logic statement
How to write statement for OR logic for switches
 

use ORL command. one more thing is that all logical operation can perform only with acc.
and for your program first move P0.1 to cy flag by MOV C,P0.1 then ORL C,P0.2

(if you are new to 8051 then you can refer book "The 8051 Microcontroller and Embedded Systems Using Assembly and C by Mazidi and Mazidi")
 

you can write logical statements as per bit operation or jump operation like jb,jbc,jc,jnb,jnc,jnz
and you also can use compare instruction to compare.
but you should go through instruction first because you can write any logical or mathematical operation using assembly.
because intelligent compiler do same.
 

I want to write assembly code for 8051

switch A is connected to P0.1
switch B is connected to P0.2
LED is connected to P1.0

IF one switch or both high then the LED is turn on otherwise turn off

switch A high then turn on LED
switch B high then turn on LED
both A B high then turn on LED
both A B low then turn off led
I want to write assembly program using OR logic statement
How to write statement for OR logic for switches

Let you try with this code,



Again: JB P0.1, LED1_ON
JB P0.2, LED1_ON
JNB P0.1, LED_OFF
JNB P0.2, LED_OFF
SJMP Again
LED_ON: setb P1.0
LED_OFF: CLR P1.0
 

Let you try with this code,



Again: JB P0.1, LED1_ON
JB P0.2, LED1_ON
JNB P0.1, LED_OFF
JNB P0.2, LED_OFF
SJMP Again
LED_ON: setb P1.0
LED_OFF: CLR P1.0

I am confused I think your code may be wrong because in my program led on in 3 times and off in 1 time
 
Last edited:

try simple OR operation.....
Code:
$mod51
org 00h
main:
mov C,P0.1
orl C,P0.2
mov P1.0,C
sjmp main
end
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top