News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

new member introduction and advice

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

Previous topic - Next topic

mineiro

I can't help you much because I know PIC only by reading, only to understand what that can do.
Please, remember, this is a masm32 board. You can get a better help in others boards/forum.

f Register file address (00h to 7fh)
Registers.
This is a memory address region where they label control/status registers.
So, exist a map in memory and each cell (memory address) have specific use.
Do you remember when I told about "some microcontrolers use specific memory addresses as registers"? Bingo.
https://www.hobbyprojects.com/pic_tutorials/tutorial2.html

PC Program Counter
The same as EIP register, Instruction Pointer. This register tell whats next code address that will be executed by cpu.
If you try to execute data, you crash system, in PIC, PC, ... . Because data will be seen as code to be executed by processor/microcontroler.

dest destination, either the W ...
d can be a W register or a status/control/... memory register.
eg: mov destination,source
    mov eax,ebx
    mov [eax],ebx

TOS Top of Stack
In PC processors, stack address start at high address (Do you remember don't touch in esp and ebp)? Yes, is this.
So, start at high address and keep going down. A push will subtract N bytes from stack and a pop will add N bytes from stack register.
Code start at low address and keep going up.
Well, what happens if both encounter? A crash.
What happens if you push a lot without pop? A crash.
What happens if you call a lot (recursive) without ret? A crash.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

q12

Very nice explanation. But I want more ideas about what that [f Register file address] may resemble in masm32.
If we can adapt it to masm32, it will be easier for me and you to work with the equivalent in masm32.
In my opinion is like an EBX register here in masm32 because as I just learned, it is not volatile and it keeps some data to be processed. Also is the most used register next to W(worker or EAX) register.

mineiro

I think that this is more close to hardware architecture. You can see a lot of these examples in ms-dos.
One example is screen. To you write some strings in screen is the same as write data strings in screen memory. Thats a fixed memory address depending on video mode (screen resolution). We can save screen by copying data from that fixed memory address to a file.
Other example is boot sector. When you turn computer on, processor will execute BIOS firmware code, and after that will jump to specific memory address (segment 0 offset 7C00h). The code at this address will start loading O.S.
BIOS offers interruptions, so we don't need know fixed memory addresses. So, to read a keyboard key we don't need know that address, we call a BIOS interruption and that code will read from port 60 (keyboard port) the data to us.
Other example is printer. We can code to print only if theres a paper in it. We need know printer status (on, paper) to print.

It's a mix between processor and system architecture, where wires are conecting.
PIC file memory area start with control/status registers, after comes General Purpose registers that can be seen as ecx,edx,ebx,... .
We can configure PORTA to be input, output or bidirectional. So can sounds more like a keyboard port. In x86 we need use in (input) or out (output) instructions to get data from keyboard port, but we need know wheres keyboard port is, that address, that number. Ohter way is to use an interruption by BIOS or ms-dos that will do that input read to us, so we dont need know ports address. Other way is to look to memory address where keyboard data is stored. So, it's complex. The easy part is to use interruption/routine/procedure/function, so we don't need understand about port address, memory address.
Interruption code are trustable code, if it fails a blue screen of death appears to us. More used in device drivers in windows.
PIC offers interruptions to be coded. When I say about boot sector, when you turn PIC on, it will start from what address? Address 0? Memory location 0?.

Link below is about PIC interruptions:
https://www.hobbyprojects.com/pic_tutorials/tutorial11.html
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

jj2007

Quote from: q12 on September 11, 2021, 01:38:15 PM
Very nice explanation. But I want more ideas about what that [f Register file address] may resemble in masm32

If I were you, I would study the Pic manual. It does have a manual, I suppose :cool:

q12

QuoteIf I were you, I would study the Pic manual. It does have a manual, I suppose
Im glad you mention this detail.
I did read many datasheets, for many PIC's, in my life.
The PIC manual is called datasheet (for each of them). So basically if you want to know the details about 12F508 for example, you search for "PIC 12F508 datasheet" in google and you will get it. Now, inside this datasheet you will not find only 12F508 information, but 2 other PIC's as well, so in total 3 PIC's: PIC12F508/509/16F505 Why? because they are very close in their architecture, limitations and options. So they stuff them all together. You must pay special attention which information you will actually read. It's not that hard. They give plenty of hints so you will be ok. The instruction set is the same across all 3 of them. And also is the same for all PIC's from Microchip, but the more they advance in pinout or internal options, their instruction list get larger. In a sense, this instruction set is the basic, the core, that is repeated to ALL PIC's families. They are in order of houndreds models (maybe thousends?, they have many models split in families). As you can guess, this 12F508 is the 12F family and is an 8bit model. 
I did program some PIC's in 2005'ish. Back then I used another PIC, 16F84A. It's a 16F family and also on 8bit. And that one it has a bit more stuff to learn in it comparative with 12F508. And 16F84 has a lot of tutorials and it is considered an easy practice. But its a bit more expensive and the 12F508 is very cheap but also very limited. Thats why I want to be able to manipulate it as thorough as possible, and they actually give code examples in each datasheet, only in assembler. I never took seriously (until now) and I concentrate on C languages to interface with them, like MPLAB 8.46(its the last), pickit2, Proteus for simulation, mplabX(now).
  Here is the datasheet for this particular 12F508: https://ww1.microchip.com/downloads/en/DeviceDoc/41236E.pdf
  For the instruction set and opcodes and some explanations over them, jump directly  to page57.
I am sincere, I did all the coding, with many successful results , using tutorials and expanding on that information to build my own code for what I needed.  But no code in assemler. Only in C - high level. Well, I did something in it's MASM, but also after tutorials and also simple stuff. But never truly understood it's instruction and its mechanics.
And I was right ! here with you guys, with your help, and the little steps I made so far, I truly start to see the mechanics, that was a big nasty blur before. I am bringing the PIC stuff in front a little bit, to create context of my direction. I will still follow and respect this forum windows masm32 direction, because I still have to nail down some more details,also thanks to your help, but from time to time, I'll make a comparison between what I just learned here with you guys and what is truly my intention with the PIC. You will indulge this little comparison of mine, even if you are not into PICs and I completely understand your point, but you are into processors and hardware with the win asm, and that is giving me hope, that I am talking with the right guys, more right than the rest out there.

Vortex

Hi q12,

My apologies if I was not clear.  I referred to the executable in my attachment. I guess you built the code as console application. No any problem.

q12

Quote from: Vortex on September 12, 2021, 06:25:21 PM
My apologies if I was not clear.  I referred to the executable in my attachment.
The LoopSample.exe just opens up and closes down very fast. It's all it does.
You should insert a keypress or wait functionality to actually keep that window open and show it's output.
Quote from: Vortex on September 12, 2021, 06:25:21 PM
I guess you built the code as console application. No any problem.
But really no need for such details, I compile the code and run it miself, it's the only way I know how to run it, from the console.

I also exercise with the push-pop, the dividing-remainder, and loop codes.  By exercise, I mean copy and play around it a bit, for familiarization.
The loop code, does not have that many comments in it, but by copying and playing with it a bit, I think is an interesting code.
What I don't understand:
-1-
.data
s1 db 'first loop',13,10,0              ;this 'data' part is like a constant, like a global line of code.
I wonder if I can insert a variable in the .data field and how to call it from code below
invoke StdOut,ADDR s1               ;will call the 'data constant' as I call it for the moment - this part I get it alone.

-2-
myproc PROC uses ebx
I want a more clear explanation of [uses] keyword from this line. I notice it before in divide.asm example:'main proc uses ebx esi edi'


Funny story:
myproc PROC uses ebx
mov ebx,3
loop1:
    print str$(ebx)
    invoke StdOut,ADDR s1
    dec ebx
    jnz loop1
    ret
myproc ENDP
I inserted     print str$(ebx)  to print the numbers. I wanted initially to use a variable inside .data, but it didnt work using  (LOCAL var1:DWORD). So, the funny story, after running the code, I see the numbers counted from 3 to 0, what? I say, but I totally forget for a moment about jnz which stands for jump if not zero. I made a list of all jump directives from the Intel book, copied in a text file and I read each separate instruction some days ago and I remembered this simple one after a moment of mind void. Not that funny, but still funny. Heh.

  So, yes, quite good sample code. It is my first serious encounter with jumps. I did see asm jumps before in other examples, in my life, but now I can definitely follow the logic. Which I'm very happy to get this far. 
Thank you !

jj2007

Quote from: q12 on September 12, 2021, 09:09:39 PM
myproc PROC uses ebx esi

This instructs the assembler to insert push+pop instructions to save these registers:
myproc starts here:
  push ebx
  push esi
  ... your code ...
  pop esi
  pop ebx
  ret

Vortex

Hi q12,

Here is another example for you :

include \masm32\include\masm32rt.inc

.data

s1          db 'This is example %u.',13,10,0
x           dd 1

.code

start:

    call    myproc
   
    invoke  ExitProcess,0

myproc PROC

    push    ebx

    mov     ebx,3

loop1:

    invoke  crt_printf,ADDR s1,x
    inc     x
    dec     ebx
    jnz     loop1

    pop     ebx

    ret

myproc ENDP


END start


In the Masm32 package, the C run-time library ( msvcrt.dll ) functions like printf are prepended with a leading crt_ to avoid name clashes.

q12

#69
To mister mineiro
In this message attachment is the updated image list. Check the attachment please.
Here is a preview: https://i.imgur.com/bYm9GtK.jpg
You give me this link: https://www.hobbyprojects.com/pic_tutorials/tutorial2.html
I read the page and also I downloaded the entire web tutorial, from p1-p13. Very good tutorial you found there.
Also thanks for the indepth explanations on my previous comparation for opcodes between PIC and PC.
I made a new, upgraded version of that list comparation now, both taking from your explanations and also from
Intel modern book. As large as it is, it is perfect if you search a specific thing, like I did today, searching
for the things you explained. (But is crazy to start to read it page by page, I felt I was going mad after a while. Haha.)
Intel book is a Very good book if you know how to use it right .
If not used correctly, it quickly becomes the book of death, hell and despair. Haha. Talking now from experience.
My image list update I made, is starting to look very interesting with all those explanations in it, as it is looking right now. Thanks to you guys here and to the Intel book that I'm starting to be more familiar with.

My next priority is to start working with data from RAM, or storage memory here in MASM32 !
I need some nice examples on this front please !

q12

To mister Votex
I looked and copied your LoopSample2 code. I see you listen to my needs and inserted a variable inside .data.
Excelent ! (and thank you)

from this code:
.data
s1      db 'This is example %u.',13,10,0
x       dd 1
What is db and dd? What they are called? Types? I think they mean double byte for the db. But I am guessing big time.
And probably dd means double doubleword? Again, Im guessing. Need clarification on them and if possible a list with all these types.

I also see that you introduced inc and dec keywords. I understand what they are.
your inc x  is written in c# as x++, and dec ebx is in c# as ebx--
I get you.
How to decrement ... lets say from 10 until 5?
How to make an IF statement in other words. How to make this:

//c# code:
int x = 10;
loop1:
x--;
if (x == 5)
{
break;  //or
goto end;
}
else
{
goto loop1;
}
end:


mineiro

Hello sir q12;
I will look to that with care later. It's morning here and today its a busy day. Maybe tomorrow you have an answer.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

daydreamer

Quote from: q12 on September 13, 2021, 11:22:23 AM
To mister Votex
I looked and copied your LoopSample2 code. I see you listen to my needs and inserted a variable inside .data.
Excelent ! (and thank you)

from this code:
.data
s1      db 'This is example %u.',13,10,0
x       dd 1
What is db and dd? What they are called? Types? I think they mean double byte for the db. But I am guessing big time.
And probably dd means double doubleword? Again, Im guessing. Need clarification on them and if possible a list with all these types.

I also see that you introduced inc and dec keywords. I understand what they are.
your inc x  is written in c# as x++, and dec ebx is in c# as ebx--
I get you.
How to decrement ... lets say from 10 until 5?
How to make an IF statement in other words. How to make this:

//c# code:
int x = 10;
loop1:
x--;
if (x == 5)
{
break;  //or
goto end;
}
else
{
goto loop1;
}
end:

check macro help files from qeditor,there is .IF .ELSE .ENDIF macros for this purpose

.data
x dd 10;dd =32bit variable=the 32bit int in c#,C++ modern compiler
.code
mov x,10 ;or m2m x,10 if assembler is sensitive and throws error
loop1:dec x ;dec=decrement = x--
.IF x==5
jmp Lend
.ELSE
jmp loop1
.ENDIF
Lend:

I think end is a keyword
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

Hi mister daydreamer
Thanks for the if-else code. It works, but I get an windows error in the very end, when it jumps to Lend.
I've also repaired your code to make it work in my qeditor. Your original code throw me a lot of assembler errors as it was passed originally.
I've also replaced mov with m2m as you comment it and still the same windows error (not assembler error)
Also thanks for the explanation of what dd means!
---