News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

new member introduction and advice

Started by q12, September 04, 2021, 12:42:56 PM

Previous topic - Next topic

mineiro

Most of that information are usefull to programmers that will create an assembler to PIC. You don't need care with that info.
PIC12f508 have a 12 bits opcode size. Any instruction to this PIC have 12 bits. (Risc). Others PIC models can have 13 bits, or more bits to represent an instruction.

Opcode means operation code. This means that each full opcode have 12 bits. Each opcode have a correlated mnemonic. We humans understand more easy mnemonics.
A not good example can be internet addresses, IP can be opcodes while www addresses can be mnemonics.

That PIC version have 33 instructions.
The Program Counter has 10 bits.
From this address https://ww1.microchip.com/downloads/en/DeviceDoc/41236E.pdf I can see that in this version the GPR start at 08h going to 1fh memory address.
This is a 8 bits microcontroler, so each memory cell have 1 byte size.
The W register is used with memory operations. So, move a data from memory to W register, and after this, move from W register to a memory location.
This info answer the meaning of "d", destination select. If result will be stored in W register or "file register".

So, looking to byte oriented file register operations opcode we have these fields (in 12 bits space).

bit 11 10 09 08 07 06 05 04 03 02 01 00
   |opcode           | d|    file      |

From bit 00 to bit 04 we have a file register address.
Bit 5 we have 0 if destination W or 1 if destination f (memory register)
Bit 6 to 11 is instruction opcode, bits that represent an instruction.

So, lets look to "addwf f,d" instruction opcode with description "add W and f":
000111dfffff
Separating these 12 bits as previous seen fields we have:
000111 d fffff
d means that the value will be stored from memory to W register or from W register to memory register.
I'm supposing, I can be wrong, you need check my words. I like to store from a memory to W register, so I need reset (zero) that bit, becoming:
000111 0 fffff
From what GPR I like to get value to be stored(added)? I choose address 10h, that in 5 bits field is 01010b. So:
000111 0 01010

I don't know about PIC notation, if right operand is destination or source. So, check if line bellow is right.
So, assembler should transform the instruction "addwf 0x10,W" in source code into that opcode.
As I say, thats an information to compiler designs or persons that created PIC assembler. Concentrate yourself only in mnemonic instructions, not opcodes, at least for a while. And concentrate in "macro assembler", assembler is to make our life easy.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

hutch--

q,

Beware of what you assume.

db = data byte. 1 byte
dw = data word, 2 bytes
dd = data double word, 4 bytes
dq = data quad word, 8 bytes and usually in 64 bit code
xmmword = 128 byte data
ymmword = 256 byte data

q12

To hutch: - Thank you for your useful information !

q12

To my very good friend here, mister Mineiro
You totally impressed me. I sincerely didn't think anyone will actually do it like you just did here. WOW.
I sincerely thought I will be the one to make the mirroring myself alone. You are totally blowing my mind with your initiative !
Bravo, and well done so far. You are on the same track with me. Absolutely amazing! Totally and sincerely.

Now, to the bizniz. I am not an expert on PICs either. I do work with them for a very long time, that is true, but extremly rarely. I will do my best as much as I can.
I know some of your description, but not all.
So until this line in your message:
"bit 11 10 09 08 07 06 05 04 03 02 01 00"
I know everything you mentioned there, and I confirm your deduction is correct.
But after that line, I am in the dark. I never thought of it like you just put it. I find it very interesting how you put it!!! I LIKE IT, actually.
I will try to search the answer to your question : "...I don't know about PIC notation, if right operand is destination or source..."
My best guess is they must probably used the same assembler syntax as the Intel processors, but cut down and customized the opcodes and mnemonics for their needs. It must be it.

I made a test program that does nothing, but I made it to figure out your question.
I am using the oldest trick in my book, the "process of elimination" and comparation !

program01:         ;we compare the other programs to this program01. This is our reference program.
#include "p12f508.inc"
org 10
Start
movlw 0 ;move literal 0 into Worker
movwf GPIO
movlw H'df'
end

and it's HEX file, generated by the MPLAB compiler:
:020000040000FA
:0400000000080008EC
:06002000000C2600DF0CBD
:00000001FF

------
program02:
#include "p12f508.inc"
org 10
Start
movlw 0 ;move literal 0 into Worker
movwf GPIO
movlw H'df'
movlw 8 ;<<<this line is new
end

and it's HEX file, generated by the MPLAB compiler:
:020000040000FA
:0400000000080008EC
:08002000000C2600DF0C080CA7
:00000001FF

----------
program03:
#include "p12f508.inc"
org 10
Start
movlw 0 ;move literal 0 into Worker
movwf GPIO
movlw H'df'
movlw 8 ;<<<this line is new + the next lines that follow down
nop
nop
nop
nop
movlw 3
end

:020000040000FA
:0400000000080008EC
:10002000000C2600DF0C080C00000000000000009F
:02003000030CBF
:00000001FF


To be sincere, after all these tests, I still don't figure out if right operand is destination or source. But at least I did something.
I really hope you are able to see the difference. 
OR
You can come with a test code and I will test it for you.

jj2007

Quote from: q12 on September 14, 2021, 04:24:42 PMI still don't figure out if right operand is destination or source.

If that is not mentioned in the manual, just guess it :thumbsup:

mineiro


program01:                             program02:                            program03:
#include "p12f508.inc"                 #include "p12f508.inc"                #include "p12f508.inc"
org 10                                 org 10                               org 10
Start                                  Start                                 Start
movlw 0                              movlw 0                            movlw 0
movwf GPIO                           movwf GPIO                         movwf GPIO
movlw H'df'                          movlw H'df'                        movlw H'df'
end                                    movlw 8                            movlw 8
                                       end                                   nop
                                                                             nop
                                                                             nop
                                                                             nop
                                                                             movlw 3
                                                                             end

:020000040000FA                       :020000040000FA                        :020000040000FA
:0400000000080008EC                   :0400000000080008EC                    :0400000000080008EC
:06002000000C2600DF0CBD               :08002000000C2600DF0C080CA7            :10002000000C2600DF0C080C00000000000000009F
:00000001FF                           :00000001FF                            :02003000030CBF
                                                                             :00000001FF


Assumptions:
First, second and last hex lines are equal to all. Maybe an initialization procedure to set some configuration or can be a structured header file.
Immediate (literal) value H'df' generally are raw dump in opcodes. So, exist hexadecimal "df" value in all hex dump. This way we have found part of that instruction and location.
I talk about "df" hex number because the opcode to "nop" instruction (no operation) is "000". And you coded "movlw   0", so "zero" in this context is not a good reference to be searched.
Well, after we found "df" so after that hex value "00" can be a good reference to be "nop".
GPIO it's a specific memory address. So, should be a constant value too, and comes before "df" imediate value. All hex dump have before "df" a "C26" value. Maybe we found a hint to part of "movwf GPIO" instruction opcode.

Reading Manual:
MOVF  f,d   001000 d fffff  The contents of register f are moved to destination d. If d is 0, destination is W register, if d is 1 destination is file register.
MOVWF f     000000 1 fffff  Move data from W register to file register

Instruction bellow have a different opcode map, because are dealing with literal.
MOVLW k     k<= 255, The "dont cares" will assembled as zeros.
bits 00 to 07  is the hex number (literal)
bits 8 to 11 its instruction opcode.

Problems:
If this is a 12 bits opcodes as told in manual, so instructions should be coded in pairs to be multiple of byte to be stored in memory. 2 times 12 bits is equal to 24 bits or 3 bytes.
Hex dump it's confuse because is being done with byte thinking instead of 12 bits. Maybe PIC is ignoring the higher bits of 2 bytes. Better, maybe PIC is reading 16 bits and ignoring the higher 4 bits to deal with 12 lower bits?
What we can do to prove this teorem?
PS: I don't read full PIC manual.

program04:
#include "p12f508.inc"
org 10                 
Start                 
movlw H'01'
movlw H'02'
movlw H'03'
movlw H'04'
movlw H'05' ;not pairs (odd) instructions, sequential increment. Hex dump should reveal something.
end                   
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

q12

YES mister Mineiro, I can see your mnemonics translated into opcode in that hex. OAU ! Pretty cool !
All I can understand it is from left to right and on a single line...hmm
I guess, by the look of it,... :00000001FF is actually the "end" command. Hmmm it is the same line in every program we tested until now.
Then.... logically, :0400000000080008EC is the "start" command and ":020000040000FA" is that include. And the "org 10" is in one of these 2 starting lines.
:0A002000010C020C030C040C050C8B - this big black line is the entire code between start and end. It looks like it.
:0A002000010 - maybe this is the "org 10" part, because I see a 10 in it. It may be. Im not sure of anything.
But not take my word at all, because I tend to make logical guesses, sometimes im right but not always. I make ton of mistakes. So... debate my logic, because this is completely not my field at all. But being between you guys here, as I said before, i start to "SEE THINGS", haha. In a good sense, of course.
- Remember, this is a completely new territory for me ! Even I have some general notions about it, still very new.
Please tell me what you think about my logic and this new result here!!! I am very curious. Also, why did you wanted so badly to see the order of the coding?


;program04: <- this label here, is not liked by the compiler, throwing weird errors.
#include "p12f508.inc"
org 10                 
Start                 
movlw H'01'
movlw H'02'
movlw H'03'
movlw H'04'
movlw H'05'
;not pairs (odd) instructions, sequential increment. Hex dump should reveal something.
end

and it's HEX file, generated by the MPLAB compiler:
:020000040000FA
:0400000000080008EC
:0A002000010C020C030C040C050C8B
:00000001FF


Also...
Before joining to this website, is what? 1 week ago? or about 10days? I made an artpage with this particular PIC12F508.
I didnt made it alone. I am not this good. I got some help and rectifications from some very cool friends I made on another forum of electronics, and those guys are professional electronists! I include myself as an electronist, but I am not one with papers, I'm just a dude who just know things. But we, in electronics also program PICs. I for example used the high level programming HitechC that is offered by mplab to program the PICs. But other guys out there are using asm from mplab. I did a very limited time use it, but I never understood it's logic and meaning of the code. They dont have the great 4777 pages book of Intel !!! Haha. Which, totally surprisingly, it did helped me understand a bunch of stuff in a very short time!!! And I got into the habit of checking the Intel book for each problem. As you put it, 'it is very well explained', but if you're lucky to find that part. So, the information for PIC asm or C, I didnt search hard enough? But I know for sure I did searched a ton back in the 2005'ish and then along time, a little bit there, another here. Now I took the problem under inspection again! And I come with the brilliant idea to talk to you guys here on masm32 forum. I get a bit more smarter with age.
- So... back to my artpage. Like I said, I got helped in making it. This is a very personal matter and I really want to make it as clear and easy as the title on it says it should be "Easy PIC". I want to make a very straight forward steps on how to program these PICS. And to put in it all the necesary steps, no matter how complicated they seem, I will make them look simple. I hope. It is my highest priority! And by god, I will make it ! But alone... I can't do much. It took me 1 week to make this artpage! Not that easy thing to make, numerous rectifications, until it got right.
On this link, you will jump in my account from this art website. Click on the image until you will see it Very big, and then right click on it and download it with "Save Image As" option. Or look for an obscure  download icon there. Download it because you will need the original jpg file to close up into it and read some text, and that is done only by zooming in.
https://www.deviantart.com/q12a/art/q20210904-EasyPIC-all-registers-890812289
You will recognize it's my artpage because of the large q12 emblem in the corner, haha.
- With your help in asm understanding, hopefully in PIC coding as well, I will be able to continue to the next artpages that I plan for. If it will work !!!! Ohoa. It will be super awesome. It's my dream!
So, thank you Super much for your Help ! (to anyone who helped me so far)

q12

#82
I also realized that I have a help book in my mplab. And like your Intel book that is made for masm32, this help book is made specifically for it's software, mplab v8.46 that I use. So I open this help and I find the asm instructions used in mplab. Imagine that. Coming here and talking with you guys, helped me a lot !!! That is for sure. It is full circle now, because I still have to learn asm in the end ! I figure either I learn it with you guys here, or directly in mplab, in the end is still asm. I think it will be faster with your help, using as we started already, masm32.

You know what will be cool?
Intel to create some PIC's ! with Intel mentality in it. From scratch. Copy or not copy what is already done, who cares, but to be easy to program them ! That's my 1 milion $ idea. I hope Intel will do it some day.

Another cool idea:
Is to be able to program the existing PIC's but with MASM32 software ! That will be very interesting to see ! To not depend only on Microchip "recipe". To have options, you know?  Like a library that is called in masm32 and will convert into whats need for PIC's. I asked this question , "what can you code with masm32?", and someone here answered "everything !". Well, im not so sure about PIC's. Haha. They are trouble.

daydreamer

Can you search for free cross development pic tools that you can install on computer?
I find it helpful with cross development tools for my programmable calculator, easy to write code on PC, simple to transfer LUT s and other data directly to calculator, than Tedious  entering on Tiny Abcdefgh...  Keyboard
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

mineiro

I think that "Start" and "end" in pic source code can be macros. Mpasm its a macro assembler too like masm32.
You can't use masm32 to create code to pic, I know it's possible, but because laws no. Well, you can create your own program to be run in Microsoft O.S. that will create code to pic. This is ok. But you can't use masm to create pic code.
Exist masm like assemblers (jwasm, uasm, asmc) that you can probably use to create pic code.

The program04 was to check a problem, now I suppose that the 12 bits opcode can be 16 bits aligned; maybe to compatibility with other pic models.

I'm using uasm assembler but can be done with jwasm, asmc to show you an example of what you can do:

Save as "pic.uasm"

.model tiny
.code
start:
db 02h,00h,00h,04h,00h,00h,0FAh,04h,00h,00h,00h,00h,08h,00h,08h,0ECh,0Ah,00h
db 20h,00h,01h,0Ch,02h,0Ch,03h,0Ch,04h,0Ch,05h,0Ch,8Bh
db 00h,00h,00h,01h,0FFh
end start

Command line to assemble this is:
uasm -bin pic.uasm

This will create a pic.BIN file that can be inserted in PIC microcontroller.

Other example to show you a macro use:
Save as "pic1.uasm"

.model tiny

movlw macro literal
db 0ch
db literal
endm

.code
start:
db 02h,00h,00h,04h,00h,00h,0FAh,04h,00h,00h,00h,00h,08h,00h,08h,0ECh,0Ah,00h
db 20h,00h,01h
movlw 02
movlw 03
movlw 04
movlw 05
db 0Ch,8Bh
db 00h,00h,00h,01h,0FFh
end start

Command line to assemble this is:
uasm -bin pic1.uasm
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

q12

To mister mineiro
Amazingly, I managed to do all that you put me to do. And in the first try ! Imagine that. Oh yes!
https://i.imgur.com/ud6JHnC.jpg
So, I assembled the 2 examples that you give me and I obtain the 2 .BIN files.
QuoteThis will create a pic.BIN file that can be inserted in PIC microcontroller.
Well, this part is problematic because I never inserted any BIN files in PIC. 
My usual routine:
I only use mplab to write the code, compile it, look inside the folder and check if it's a hex file there.
After that,  I open another program called Pickit2 Programmer that is only importing hex files.
I am importing the hex file and press the "Write" button.
Next, it will transmit this data through usb cable, to a device (a programmer) that is called Pickit2, connected to a prototyping board that is holding my real PIC12f508 in it.
the real Pickit2 Programmer + testing board + the testing PIC12F508 on it:
https://forum.allaboutcircuits.com/attachments/working-pic-12f508-program-jpg.238721/
the software also called "Pickit2 Programmer" to confuse the shit out of people:
https://pic-microcontroller.com/wp-content/uploads/2013/04/PICkit-2-Programmer.png
I think we must convert this BIN file into HEX, and write it into PIC as im usually doing it. If it is another way, DO TELL ME ! Im all ears ! Actually I do believe there are more 'direct' ways to interface a PIC, without the 'more helpful hardware' bulshit. I am quite happy with my antique pickit2 programmer! It has it's bugs, but is very good after you learn what to avoid. Again, Im actually using it quite rarely, years apart. Only recently...probably from 1year or so I started to remember everything from my younger life. I know for sure I did some asm tutorials back then and I want to continue the same path as I started. I remember something, but not complete. Back then I was in fire, now, the fire is only in my memory. I loved that fire...  :eusa_boohoo:

To mister daydreamer:
QuoteCan you search for free cross development pic tools that you can install on computer?
I find it helpful with cross development tools for my programmable calculator, easy to write code on PC, simple to transfer LUT s and other data directly to calculator, than Tedious  entering on Tiny Abcdefgh...  Keyboard
- I sincerely have no idea of anything you just mention here. I search "cross development" in google myself, but all I can find is "mobile cross development", but nothing related to windows or pic. I have no idea what "cross development" even means.  Wait, I just google what this means and it is "various methods to accommodate different operating systems or environments for one application or product". That's interesting ! I know about it as a general information but 0 experience with it.
You are mentioning about a "programmable calculator" - can you show me a picture about it? Or a webpage that describes it? It can mean anything. Also mentioning about the "LUT". I guess it is an acronym for something. What is it? Also mentioning about "Tiny Keyboard" - again, show me some pictures, because I have no clue what you are looking at.  Thank you for the contribution. I hope you can bring some light into the matter.



daydreamer

https://education.ti.com/en/products/computer-software/ti-connect-ce-sw
this is my cross development tool on PC and my kind of calculator

LUT= Look Up Table,often used with precalculated math functions table,to speed up things
for example a sine and cosine LUT when drawing circles
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

q12

I downloaded the installation kit from the link page you give me.
I wanted to install it, but I was prompted with this:
https://i.imgur.com/lGkABwD.jpg
I guess, they dont like windows7 anymore. It's pity it didn't work for me. Oh well. I tried it at least.
- Also, you should specify the things that you are working with a bit more complete. Just calling it "calculator" is way too general.
"A graphing calculator (also graphics calculator or graphic display calculator) is a handheld computer that is capable of plotting graphs, solving simultaneous equations, and performing other tasks with variables." So... from now on you should say you have a "graphing calculator". Way more easy to search for it on google and to be identified ! Just remember in the future. I bet such tool is extremely expensive as well.
What I get from you, is future attention to "cross development" tools or software. Thanks and I think is a nice idea. I wouldn't think of this myself. Very interesting point, mister daydreamer.

mineiro

Bin files are raw data, like rom files, like hex files, ... .
Rename pic.bin to pic.hex.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

q12

mister mineiro:
QuoteBin files are raw data, like rom files, like hex files, ... .
Rename pic.bin to pic.hex.
I didn't know this detail ! Thanks for telling me. I changed the file extension into .hex and loaded it into pickit2 programmer.
Here is the result imediatly after loading the file in it :

Configuration file for PIC's is the death of me. I always had problems with it. Until I get it wright from tutorials.
(I copied this line from a working program so it should work fine if you find the way) The configuration looks like this:
__config _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC
I also Write the PIC even if I got that warning. But nothing happens. This is because by default it's GPIO port is set to input. In program, we set the pin as output to actually lit a led on its pin.