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

q12

Check this out:
I put in this message an attachment with an entire mplab project folder. The code is about: all 4 leds from my testboard will blink at once, in 1s interval.
The most important files for you are:
12F508-d.ASM
P12F508.INC - this file I copied from mplab installation folder. Lucky you, I have a nose for cracking stuff, not much, but a little bit I like to look inside stuff. So I know how to find Some Stuff. So this file is taken by the compiler directly from instalation folder and not from project folder.
I just looked inside it and it contains some useful asm instructions, that I am not familiar. But I imagine it will help you greatly.
PIC12F508.hex  already compiled hex file from mplab.
I totally forget to mention this tiny detail... From mplab I can run fine any asm program and write it directly into PIC, without making all these supplementary steps with the hex and the Pickit2 programmer software. That is an alternative for C programs that microchip not really likes it and they intentionally bug and error them. It's my observation. The intention was to make this mplab only asm from start and is build for that very robust, and it shows that is doing a good job of it.

mineiro

I'm looking to that file now.
You will deal with include files in masm32. EQU means equates, so, if you like to create a constant and use that constant by name in your code you can do with EQU.
Something like:
TRUE equ 1
FALSE equ 0
GPIO equ 6

I think I got the point about that .hex file. That's a "hexadecimal string" initialized with ":". So, bin files will not work like I was thinking.

--------edited-------
can you try this?
Save as pictest.uasm

.model tiny
.code
start:
db ":020000040000FA",0dh,0ah
db ":0400000000080008EC",0dh,0ah
db ":0A002000010C020C030C040C050C8B",0dh,0ah
db ":00000001FF",0dh,0ah
end start

assemble with "uasm -bin pictest.uasm"
rename .bin file to .hex and try to insert in pic.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

q12

Quotecan you try this?
I will try anything you put me to. I am speechless and in wow mode. You are so cool by helping me with this!
I assembled your new asm code, changed its extension, load it in pickit2 but... the exact same Yellow window as before:
"Warning: No configuration words in hex file."
In the previous message I put for you a .zip file. Inside it you will find this: P12F508.INC file.
It contains all under the hood PIC directives. Look in it and choose the correct bits of it's configuration.
If you did already this step, then you're ok.
In this time, SOME lines that mplab generated for us in more other successful *.hex compiles, I copy them into your new [pic.hex] code here and adapted to it's way of code. It didn't work so far, same yellow warning.



q12

#93
Hope this WORKING example, helps !
I did a simple test:
I copied the entire FULL hex code from a mplab generated hex into your (new syntax) pic.hex

Original mplab generated hex file content:  (it is blinking only 1 led)
:020000040000FA
:10000000080C0600DF0C0200FF0C25006600010C46
:1000100026000D0966000D09070AFF0C010CF0020D
:080020000F0AF2020F0A0008AA
:0400280000080008C4
:021FFE00FE0FD4
:00000001FF


And adapted to your code syntax that is new to me:
.model tiny
.code
start:
db ":020000040000FA",0dh,0ah
db ":10000000080C0600DF0C0200FF0C25006600010C46",0dh,0ah
db ":1000100026000D0966000D09070AFF0C010CF0020D",0dh,0ah
db ":080020000F0AF2020F0A0008AA",0dh,0ah
db ":0400280000080008C4",0dh,0ah
db ":021FFE00FE0FD4",0dh,0ah
db ":00000001FF",0dh,0ah
end start


And it works like a charm !!!
So I tested your syntax and it is fine.
Hope this WORKING example, helps !

I have also updated my artpage with new and more complete informations:
>> https://www.deviantart.com/q12a/art/q20210904-EasyPIC-all-registers-890812289

mineiro

So, we have a start point to play.
Sounds to me that exist a pattern in that .hex file that need be investigated.
:10000000080C0600DF0C0200FF0C25006600010C46
:1000100026000D0966000D09070AFF0C010CF0020D

I don't have a pic to try and test. So, I think my PIC adventures ended here sir q12.
If you have difficulties just post.
Good luck.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

TimoVJL

Is this useful for testing ?
PICSimLab - Prog. IC Simulator Lab.

Link collction:
http://www.picemulator.com/links.html
May the source be with you

q12

Mister Mineiro, thanks a lot for your involvement ! My hat is off !
I learn some very interesting things form you in this little experiment: how to use an external console asm compiler Uasm for example. The little details in this entire experience sum up. It was a  fantastic road. Very cool ! I like it.
I will still ask problems of assembler and I hope you will be around, because this problems will build up in time. I am re-learning PIC assembler in this time, I remade my artpage also, and I will definitely need clarifications in the near future. I also find some very straight forward pic tutorials.
I am sincere when I said I am mirroring windows asm with pic asm, to learn better and more mechanics and tricks !!! I didn't do it too much yet, well, I got a kick start with masm32 here with you guys, and it helped me a lot. I will continue the lessons, but in the same time I will concentrate more on pic asm side. We'll see how the wheel is spinning, nothing is fixed. You know how it is. Also, ideas will build in time so now is trouble, but tomorrow you will "SEE MORE". Haha. Trust me, it is like that.
Bottom line: I did an immense step, by only starting this thing. Now I may say, I got inertia. So it is a great thing. I am very proud I reach this far. At least you know where I come from, you know my direction so you know im dead serious in my slowly but surely walking forward to the highest mountains of knowledge. Hopefully...Heh.
I will not insist on mpasm since we did a little test until now and I understand.
- But I will insist on masm32 lessons until I will be independent enough. Huuh.
By the way !!! How many years do you have of asm? 10?20? I bet is long time. For me was always a struggle, and the most important motif was not doing it every day. Because my profession and career is diametral oposite than programming of any kind. I do it anyway.

To mister TimoVJL
Very interesting simulators links! I will definitely look into them.
I also dig into the darkest memories I have about using mpasm, by dark I mean 95% forgotten, and I managed to dig out some very vague ideas about mpasm viewers. I know I didnt use them a lot, but I know I used something.
Check how my mplab looks now, hahahaha:  https://i.imgur.com/AlkzGER.jpg This is in debugger mode and can not write to pic anything. It's only simulating environment. But I don't have much of a clue how to deal with this informations... I have not much experience.  Im doing small steps.

daydreamer

 :thumbsup:
you going to get more hardware later,2 Digital to analog converters and oscilloscope x and y intake I had in school,you could make vectorgraphics games
many here has asm background since Amiga was new(1980s) or few years earlier,imagine ca 1980-2021 how many years asm experience :greenclp:
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

hello sir q12;
Of course that if some problems appears we can talk about that. Feel free. I'm involved in other projects and lost focus when giving time to PIC. I hope you understand.
Probably 30 years with x86, started with ms-dos. Before that was zilog-80 (z80). But I really started to understand instead of just apply years later.
I started with monkey see monkey do technique. Now I understand better didatic and methodology, learning curve, stagnated times, time to osmosis, and learning curve grow again, ... .
There's no answer why we need stay stagnated in time to occur an insight and learning curve grow.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

q12

I am VERY curious what your answer will be for:

Is there any difference between these 2 commands?
b'00001000' and 0b00001000 ?
Please specify what they are?

mineiro

Is there any difference between these 2 commands?
No

b'00001000' and 0b00001000 ?
Please specify what they are?
Binary strings.

Programming languages need one way to represent binary numbers. They use "binary strings" that will be converted internally to binary numbers.
Your example use "prefix" instead of "suffix". In masm notation that will be 00001000b (suffix).

It's necessary create some differences. The symbol "0" that you have seen now is not "number 0" inside computer.
Years ago, each hardware guy was creating their own processor. And they created their own "symbols table" to be shown in screen/printer. So, internally, if I was in some machine and like to represent "symbol 0" I need create some internal bits to represent that. In other hardware, to I need represent "symbol 0" I need create another bits different from first hardware. To create compatibility comes ASCII code.
Now yes, if your hardware and my hardware understand ASCII this means that if I output symbol 0 in my hardware so your hardware will be the same. Compatibility. Now both hardware can understand same symbols as being same internal binary representation.
My computer is different from yours, how can you understand me? ASCII code.

If you look to ASCII table, the "symbol 0" (if you continue thinking in "number zero" you're out, remember, symbol) is represented internally by hexadecimal "30h". So, to echo internally zero I need convert that to 30h. And going in reverse way, if user press in keyboard "symbol 0 (key 0)" that is "30 in hexadecimal base", and should be converted to "number zero" to be used internally.
You will get the point if you understand binary/hexadecimal/decimal/octal base conversion and "symbols" used to represent that.

Idea is simple. You have 8 parallel wires. Each wire can have electrical current or not. How you represent this? Persons choose what we know as being numbers to represent that, in this case, 0 or 1. An old writer choose "letter"(symbol) a or b to represent that, I think was Francis Bacon.

So, answering you:
You will input that 00001000b by using keyboard, and keyboard will store "symbols" that we understand as being number 0 but in reality is not number zero internally to a computer (ASCII table). So, assembler/c/C# will convert that symbols to represent an internal binary number that will be seen as quantity.
And that internal binary number if shown in screen/printer can be a symbol, or a sound (music), or an pixel (image).

Who define what data means are us, programmers.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

q12

Excellent answer ! Even some information you exposed is known to me, other points are new or totally buried and forgotten.
The answer I was looking for is here: "Years ago, each hardware guy was creating their own processor. And they created their own "symbols table" to be shown in screen/printer. "  Your explanation here, fit perfectly with what I find and also microchip explanation.
I know I am presenting a PIC asm code here, and I apologize for it, posting it here, but it is the entire context very well summarized in it.
I did test these things for around 2 days, coming back again numerous times, with breaks. Hammering is the best word.

Scroll down in this code to see the final answer from Microchip forum, AFTER I reach my conclusions and finished my tests.
I already resolved the problem and find a solution: to not use that 0b... opcode.
Their answer was not was I expected ! That's why on internet you will find so many not working codes for pic's assemblers and hilevel as well.
This was a very illuminating experience. Im very glad I get the context on everything.
What I was expecting/believing originally as an answer from both parts (you masm, and them microchip), was different meanings in code and specific usage of these opcodes. But it turned out to be completely different usage and context than what I believed.
- I wonder if its the same situation for masm as well, where different opcodes are mingled on the internet, and they come from different asm languages with different sintaxes and naming? You've already presented me the uasm console asm compiler, but in my very short usage of it, I didnt spot any diferences from masm (not that I use it very long as well) haha. Is my belief that uasm is like a mask over masm. I am way too curious? Haha.
Also, I find opcodes that are from masm or win asm, written for pic codes. I find 1 example in all my research, and seeing you mentioning the 00001000b opcode now, it pop the "aha". I am inclined to believe(well, for a long time actually) these code samples on internet, a large majority of them are intentionally screwed to not be able to use them staying comfortable at home.
From this perspective, this part was the hardest for me, the greatest impediment, when I was learning pic asm back in time. Now as well, I can not differentiate between that guy opcodes or symbols as you put it, or the other guy. Especially in the beginning of learning with a minimal experience.  I like things to be black and white. Who doesn't?
Oh,oh, also I play with the binary code and I figure out, also I asked microchip and they clarified this thing for me: there are bits in their registers, that are not implemented ! So basically you can write whatever to those bits, it will not matter. So in other words, a register with 6 bits in it, is actually a 8bits but with 2 bits unimplemented. I didn't ask yet, but I will, about 16bits register, but my big impression its 4 bits are not implemented, and the register appear as 12bits, for our delicious confusion.If you pay attention in my code, I am writing the full 8 bits in the opcode: for ex: b'00001000' has 8bits in it, but everywhere else, on every tutorial, is written as 4bits in this case: b'1000' or the large majority of encountered codes as 6 bits. And it works fine with how I am writing it as 8 bits !!! No problem.
So...
my test code is like this:
include "p12f508.inc"
__config _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC

org 0
clrf GPIO
;0b... is accepted by asm compiler but is a wrong command !!!
;I got a ton of errors using 0b....
;MOVLW 0b00111111
;MOVLW 0b00001000

;b'...' command is the only CORRECT command to use
MOVLW b'00111111'
;MOVLW b'00001000'
tris GPIO

    movlw 0xDF
    option
    movlw 0xFF
    movwf OSCCAL
Start
;MOVLW 0b111110
MOVLW b'111111'
MOVWF GPIO
END


;Microcip Clarifications:
;The b'00001000' is used by the MPASM assembler, and 
;the 0b00001000 prefix is used by the PIC-AS assembler (and XC8 C compiler).



;Microcip forum explanation:
;radix dec
;Unfortunately the default radix of MPASM is hexadecimal;
;that is, unprefixed numbers are hexadecimal numbers.
;So, for example, 0bad is hexadecimal number 0x0BAD (0b00001000 is actually 0x0B00001000).
;That is the reason why I always set the radix to decimal with
;list r=dec or 
;radix dec
;Setting the default radix to DEC also avoids the stupid dot syntax for decimal numbers.
;00000100B is documentated in XC8 Compiler pdf. ;It is read as a backward label (temp) if lowercase.
;That is the binary syntax for the ASPIC and ASPIC18 assemblers.

;in Conclusion: learn what to use and what NOT to use.




q12

Here is another test code I made.
Notice in it, that I used 8bit per opcode and I did it like that because it is coinciding with the actual datasheet (or manual) specific register bits.
In this case the GPIO register: https://i.imgur.com/r15ZBFp.jpg
but also for oscal and option registers.
include "p12f508.inc"
__config _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC

org 0

;close every pin in GPIO
    ;MOVLW b'000000'
    ;MOVWF GPIO
    ;or
    clrf GPIO
         

;GPIO configure pins as output or input
;All I/O pins are: GP5,GP4,  GP2,GP1,GP0    GP3 is input only
;MOVLW B'xx001000' = xx is not implemented in the PIC
;MOVLW B'00001000' = all I/O pins are 0's (as output) where 1=GP3 is always input
;MOVLW B'00111111' = all I/O pins are 1's (as input)
;MOVLW B'1000' is a simplified way for B'00001000'


    ;movlw 0x08
    ;tris GPIO
    ;or
    MOVLW b'00001000'
    tris 0x06


    ;movlw 0xDF
    ;or
    movlw b'11011111'
    option


    ;movlw 0xFF
    ;or
    movlw b'11111111'
    movwf OSCCAL


Start

;GPIO is at adress 06h if you look in the datasheet
;so, [MOVWF GPIO] and [MOVWF 06h] is the exact same thing

    MOVLW B'000010'
    ;MOVWF GPIO
    ;or
    MOVWF 06h

END

mineiro

Each assembler have their own notation, own syntax, own semantics, ... . We need follow their rules.

As you perceived, by default mpasm use hexadecimal base (radix) and you can configure mpasm to use decimal base as default by inserting "radix dec" probably at some place at start of source code. Masm32 use decimal as default.

;GPIO is at adress 06h if you look in the datasheet
;so, [MOVWF GPIO] and [MOVWF 06h] is the exact same thing

You can use EQUates in your code like:
FINE EQU 1
MOVLW FINE
If you look that file "p12f508.inc" you will see a lot of EQUates like GPIO,OSCCAL as example.

ORG means ORGanize. This will instruct assembler to organize at certain memory address.
Org 0 means to organize data/instructions at memory address 0.
Probably exist one way to do that using "org 6" or "org GPIO" and configure/setup that memory address.

I think that "__config" line in source code is creating a binary number (byte) by seting/reseting some specific bits in 8 bits field.
In masm32 we do that like:

one equ  00000001b              ;eg: GP0
two equ  00000010b              ;eg: GP1
four equ 00000100b              ;eg: GP2
three equ (one or two)          ;00000011b
seven equ (one + two + four)    ;00000111b

OR boolean gate have an addiction meaning in logic operations. AND have a subtraction meaning in logic operations. By logic operations means that is about logic. Look example bellow:

wrong equ (one or one)          ;00000001b  ;don't added because it's logical operation
two equ (one + one)             ;00000010b  ;added because is arithmetic operation

So, "__config" line used AND (&) operator. You need probably check the meaning (equ) of MCLRE_OFF, _CP_OFF , _WDT_OFF , _IntRC_OSC .

Oh, so, you can create your own config/include files and insert that line in your source code. One observation is take care with duplicates or used names in "p12f508.inc" or with reserved mpasm words:

...
include "p12f508.inc"
__config _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC
include "q12config.inc"
org 0
...


q12config.inc

FINE EQU 1
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

daydreamer

Quote from: mineiro on September 20, 2021, 09:12:11 PM
As you perceived, by default mpasm use hexadecimal base (radix) and you can configure mpasm to use decimal base as default by inserting "radix dec" probably at some place at start of source code. Masm32 use decimal as default.
good to know is you can change masm decimal as default for example in .data section that you write in lots of hexadecimal data,make it easier to temporary change to hexadecimal as default
changes syntax in that section to no need to end hexadecimal number with 'h',but if you have an exception where you use decimal number,end it with 'd' in that section
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