Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

understanding simple addition program

Status
Not open for further replies.

Parth86

Member
Hello again, need to understand simple addition program for 8051
I have done little work please check out

Instruction - mov , add
Register - A ,R1
address- ROM Address, RAM address
data - 02,03 and 05

ADD- 0001
MOV -0010

A register= 01
R1 register=06

A register at rom address=8001
R1 register at rom address=8002


Instruction + register +address +data
mov + A + # +02
0010 +01 +8001 +02

we can say that mov A, #2

0010 06 8002 03

we can say mov R1,#3

and 0001 01 06
add A, R1

now this result will be store somewhere in ram address like 7001
 
I see a few flaws in your thinking.

mov R1,#3

Aside: I hate this notation. When I think of "Move", I think move object A to B not the other way around. I think of Load as load A with B. But, that's how some systems are.

The #3 is MOV Immediate. So, let's say that the instruction expects the #3 to be in the next word. e.g. That's where the compiler put it.

The other problem is a register would not be in RAM or ROM. It's a register or an entity in the CPU.
 
I see a few flaws in your thinking.



Aside: I hate this notation. When I think of "Move", I think move object A to B not the other way around. I think of Load as load A with B. But, that's how some systems are.

The #3 is MOV Immediate. So, let's say that the instruction expects the #3 to be in the next word. e.g. That's where the compiler put it.

The other problem is a register would not be in RAM or ROM. It's a register or an entity in the CPU.
Mov A, #02 ; data 2 will be store into register a
Mov R1 #03 ; data 2 will be store into register
Add A, R1 ; alu will do addition

result will be 05 it will be store in ram location
Code:
Mov A, #02   ; data 2 will be store into register a
Mov R1 #03  ; data 2 will be store into register
Add A, R1     ; alu will do addition

How does we know that which ram location we are using store result 05
 
Because the instruction "Add A, R1" is defined that way OR it's better written as "Add (A), R1"

Which again, is architecture specific. "Add (A), R1" in THIS CASE would mean add R1 to the the address pointed to by A.

Notations like: R1, (R1), -(SP) and (SP)+ are common:
R1 = Contents of R1
(R1) = address pointed to by R1
-(SP) = Use something from the stack and decrement the stack pointer
(SP)+ = Put something onto the stack and increment the stack pointer when done
 
Because the instruction "Add A, R1" is defined that way OR it's better written as "Add (A), R1"

Which again, is architecture specific. "Add (A), R1" in THIS CASE would mean add R1 to the the address pointed to by A.

Notations like: R1, (R1), -(SP) and (SP)+ are common:
R1 = Contents of R1
(R1) = address pointed to by R1
-(SP) = Use something from the stack and decrement the stack pointer
(SP)+ = Put something onto the stack and increment the stack pointer when done

what does mean by address?

rom has address
ram has address
I/o has address
can you explain address for ram rom and I/O ?

Instruction + register +address +data ; statement for my understanding
mov + A + # +02 ; assembly code
0010 +01 +8001 +02 ; just for example we can say this is hex code
IS it correct statement for basic understanding ?
 
what does mean by address?

rom has address
ram has address
I/o has address
can you explain address for ram rom and I/O ?

It's architecture again. In many processors now, addresses are indeed rom, ram and ports. Ports may have specific addresses. CPU registers can even have addresses.

0010 +01 +8001 +02 ; just for example we can say this is hex code
IS it correct statement for basic understanding ?

No

Hex is just a number system, but it turns out that both HEX and Octal can be easily converted to binary.

so
1010 1101 b
is nothing but 8+2; 8+4+1 or ADh

but if you re-arrange it in groups of 3:

010 101 101 ; (I put a leading zero) you get
2;5;5 or 255 Octal
 
It's architecture again. In many processors now, addresses are indeed rom, ram and ports. Ports may have specific addresses. CPU registers can even have addresses.



No

Hex is just a number system, but it turns out that both HEX and Octal can be easily converted to binary.

so
1010 1101 b
is nothing but 8+2; 8+4+1 or ADh

but if you re-arrange it in groups of 3:

010 101 101 ; (I put a leading zero) you get
2;5;5 or 255 Octal
Instruction + register +address +data ; statement
mov + A + ? +02 ; assembly code
01 + 10 + 01 + 01 ; binary digit

hardware understand only machine code
If instruction will fetch If alu get bit 01 it will do addition If it will get another bit it will do another operation

so I made bit pattern for Instruction , register, data and address just for learning purpose
 
Last edited by a moderator:
What you really did is a part of Lexical analysis: See: https://en.wikipedia.org/wiki/Lexical_analysis

More like the stuff you need to do when writing a compiler. It's a step before machine code.
everyone say start with basics so I am trying to understand in this way

Instruction + register +address +data ; statement for my understanding (idea)
mov + A + ? +02 ; assembly code ; statement for assembler (assembler)
01 + 10 + 01 + 01 ; binary digit ; statement for controller
off on + on off +off on +of on ; transistor on off
0,5v +5v ,0v +0v , 5v +0v 5v ; voltage level

can anyone help me In this way
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top