The MASM Forum

Miscellaneous => Miscellaneous Projects => Topic started by: q12 on September 04, 2021, 12:42:56 PM

Title: new member introduction and advice
Post by: q12 on September 04, 2021, 12:42:56 PM
Hello,
I am a brand new member and I am new to assembler. I know SOME stuff, but not that much. I am a rookie but not from 0, but from 5. I have some notions and I read some assembler articles. I also did code a little bit of pic mcu, like 12F508 and 16F84. Again, Im not that new.
I have an idea about masm32... I install it already on my current OS (windows7)
My priority is to learn asm for PIC's. I imagine this asm comunity is more responsive than microcontroler comunity (in general); so thats why I redirected here with you. I hope I am right. My hope is to learn windows asm more faster than with microcontrollers. At least a good introduction and to spin my wheels.
I am looking forward to learn a little bit more about this thing.
Any constructive thoughts are welcomed. Links, tutorials, videos, anything that will push me faster and further.
Thank you very much!
Title: Re: new member introduction and advice
Post by: jj2007 on September 04, 2021, 06:36:08 PM
Hi q12,

See Masm32: What you absolutely need to get started (https://www.jj2007.eu/Masm32_Tips_Tricks_and_Traps.htm) for some basics. You are optimistic with regard to help from the Masm32 community for PICs. Members here are very helpful in general, but almost nobody works with PICs...

Welcome to the Forum :thup:
Title: Re: new member introduction and advice
Post by: q12 on September 04, 2021, 10:22:29 PM
Excelent! Thanks for the help! I will start look into your recomandations.  :thumbsup:
The PIC's are my problem, or better say, is my drive, my end goal, my destination.
I want a foot in the door with assembler, and I am struggling for years with it, (from 1998) and with great(also years) breaks between attempts. I started some tutorials, many years ago, I understood them for a couple of days, and by not repeating, I forget everything I learned and exercised back then. But at least I know it is possible. Haha.
But now, I say enough. I want to commit to it. So I had the great inspiration to get a turn into masm assembler, its out of the box thinking for me. I really hope it will help me develop a minimum of "foot in the door". I dont expect much. A little is enough for me. You know, I am thinking like the person who didnt have it and when it does, is happy with as little as he can get. Thats totally me right now.
I want you mister @jj2007  to give me a summary of what you can build with masm.  From my general knowledge, I know is hardware dependent, and more precise, CPU and ram dependent. If Im not mistaken GPU dependent as well (in videocards) since now exists GPU+CPU on the same board. What im more interested is what do you usually do with masm, give me some details. Tell me your story, or general stuff, to push me more forward.
Thank you for now and I expect great help from you !   :wink2:
Title: Re: new member introduction and advice
Post by: q12 on September 04, 2021, 11:30:19 PM
Updates for the help so far
(It is a good thing to offer an alternative link, on Google Drive, or similar)
-When I click on your link there (the red marked one)
(https://i.imgur.com/u8kmgs0.jpg):
-The page is not loading
(https://i.imgur.com/2wG0LYK.jpg):

Title: Re: new member introduction and advice
Post by: TimoVJL on September 05, 2021, 12:11:37 AM
Perhaps Siekmanski can help you, as he knows some MCUs.
Title: Re: new member introduction and advice
Post by: q12 on September 05, 2021, 12:53:31 AM
Thank you mister @TimoVJL
Interesting idea, but I really meant what I said. I only want to get some good introduction, to learn it a little bit. To start my wheels spinning.
Also, I dont want to bother anyone important here with my rookie problems and especially on completely other direction than the masm you are working with routinely.
In the near future, I will certainly consider your idea, to search for people that know MCU asm... but until then, I need to get my feet wet. I feel im not ready for any serious discussion on that level yet.
Plus, I will learn some new tools, new concepts, I know for sure they will be new. Haha.
Btw, I already collected and installed, a bunch of recommended tools from masm32 [intro.txt] file
(https://i.imgur.com/X7hOLjb.jpg)
and this forum page link(s).  Pity I could not continue with the MasmBasic package link. I hope it will get resolved soon. I finished the first page to read and also downloaded the recomanded pdf book in there: [Art Of Intel x86 Assembly.pdf]

So, I'm doing my homework as best as I can.
I know is hard. I'll give it my best.
Thank you.
Title: Re: new member introduction and advice
Post by: jj2007 on September 05, 2021, 08:55:08 PM
Quote from: q12 on September 04, 2021, 11:30:19 PM
Updates for the help so far
(It is a good thing to offer an alternative link, on Google Drive, or similar)
-When I click on your link there (the red marked one)

Sorry, I changed provider some time ago and forgot to adjust some links. Try again with Ctrl F5 to refresh the cache. (http://masm32.com/board/index.php?topic=94.0)
Title: Re: new member introduction and advice
Post by: q12 on September 06, 2021, 12:15:57 AM
 - You made another mistake with the links.
[Hello world] page contains a link to [MasmBasic] page and the link inside [MasmBasic], the red marked one, opens back the [Hello world] page. So it's full circle now.
(https://i.imgur.com/DRXtznt.jpg)
---
- Hey, it's ok, really, I will learn masm as it is , without [MasmBasic] thing, which I truly have no idea what it does in reality, and I will use it a limited time anyway, since my rookie level. Sincerely, it's ok if you can't fix the link.
- I will need your advice from time to time though, while working in the normal masm32. I will follow a tutorial of course for it, but it will be great if I will get some feedback at some points there. Thanks in advance. And I really wish I can start and continue practice this very hard thing. We'll see. All in good time.
Title: Re: new member introduction and advice
Post by: daydreamer on September 06, 2021, 03:37:31 AM
Welcome Q12 :thumbsup:
Quote from: q12 on September 04, 2021, 10:22:29 PM
I want you mister @jj2007  to give me a summary of what you can build with masm.  From my general knowledge, I know is hardware dependent, and more precise, CPU and ram dependent. If Im not mistaken GPU dependent as well (in videocards) since now exists GPU+CPU on the same board. What im more interested is what do you usually do with masm, give me some details. Tell me your story, or general stuff, to push me more forward
you can do anything in masm,but for SSE2 instructions or later you need to get a later ML version,than included in masm32 package
do you use your computer for crossdevelop PIC to make it easier?
I use crossdevelopment tools on PC for programmable calculator,much more convenient than type directly on annoying tiny keyboard on calculator
Title: Re: new member introduction and advice
Post by: hutch-- on September 06, 2021, 10:05:04 AM
Hi q12,

First, welcome on board, you will have a ton of fun here as many people well understand 32 bit MASM. While starting out, stick to the installation of MASM32 and once you get the swing of it, you can tweak whatever you like and add whatever you like. When you have been at it for long enough to understand it better, you can use a later version of the assembler ML.EXE.

PIC is not my field but if you get the swing of instruction sets and the inherant logic of using assembler instructions, the transition to PIC assembler may becomes a bit more familiar.

Something that is very useful when you are learning the instructions is a simple console form of executable as it isolates you from the complexities of Windows user interfaces so you can concentrate on just the instructions and how to use them.
Title: Re: new member introduction and advice
Post by: q12 on September 06, 2021, 11:38:41 AM
Hello mister @hutch
"PIC is not my field but if you get the swing of instruction sets and the inherant logic of using assembler instructions, the transition to PIC assembler may becomes a bit more familiar."
-  I could not say it more better than you said it !!!  It is Exactly my original thought. My believe is that learning a bit of "true" assembler, or the "origin" like masm32 here, (again) I believe it is, the correct way and will enhance my skills, especially with my "target" PIC's coding (at which I suck !greatly!).

"Something that is very useful when you are learning the instructions is a simple console form of executable as it isolates you from the complexities of Windows user interfaces so you can concentrate on just the instructions and how to use them"
- I think you are pointing out that using only "cmd" console ... (the cmd.exe in windows/system32 folder), will help me focus only on the instructions themselves. I think  I understand you now. The thing is... I am absolutly Not familiar with using a console for writing asm. I only used a console for directives/commands to windows folders and some files and some other console type programs, like for example youtube-dl.exe (which is fantastic good by the way). Heh. Yes, pretty new idea with asm in console for me.
- How do I use asm in console?
Any good starting tutorials for me? I am very interested in themes, problems to resolve, that will help me advance in my asm learning. If you happen to know some "problems" to resolve and learn with them, for starting people like me. Or write a list yourself, it should not be that hard for someone experienced. I thank you in advance for them!
Title: Re: new member introduction and advice
Post by: hutch-- on September 06, 2021, 01:41:49 PM
A console app in asm is still written in assembler, its RUN from the console and only has a simple console interface. The MASM32 SDK has a directory of tutorials which would be useful for you to have a look at.
Title: Re: new member introduction and advice
Post by: q12 on September 07, 2021, 01:53:58 AM
I did try it before your recommendation and it didn't work.
But today I tried a bit more than before... because I believed in your advice.
And the FIRST program in [demo1] folder, namely the hello.exe didnt output anything.
But, I said to try the next [demo2] folder, namely the proc.exe and that, for my amazement, it worked. Ohoa ! That is something.
Hey, thanks for the influence ! Good influence ! Hehe.
(https://i.imgur.com/Hqp6j8k.jpg)
Title: Re: new member introduction and advice
Post by: HSE on September 07, 2021, 04:31:12 AM
Hi q12!

Open hello.asm with QEditor.

Use menu Project > Console Assemble & Link.

Regards, HSE.

Title: Re: new member introduction and advice
Post by: q12 on September 07, 2021, 05:34:12 AM
Hello mister @HSE
Thank you, that worked.
I am copying and thinking as much as I can on the directives I see here. They look very close to a high level language. I personally know c#, and I already was introduced to a method/function that here in asm is called "procedure". Fantastic. I presume all that bunch of include files in the begining of each code, is actually enable this high level feel. I think is cool....Until I reach the numbers part.Hehe.
I am playing with the code I just copied, to familiarize myself and I didnt finished the console tutorial yet. I plan to make in the end a custom code, with the things learned in this compact tutorial. I'll update you soon.
- And thank you for your support so far !
Title: Re: new member introduction and advice
Post by: hutch-- on September 07, 2021, 09:04:10 AM
Hi q,

Here is a small test piece for you. Save it as an ASM file in a directory by itself then build it as a console app.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey                           ; wait for a key press to exit
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    push esi                        ; save esi

    mov esi, 500
    add esi, 500                    ; ADD
    print "Result 1 = "
    print str$(esi),13,10

  ; ---------------------------------

    mov esi, 2000
    sub esi, 1000                   ; SUB
    print "Result 2 = "
    print str$(esi),13,10

  ; ---------------------------------

    xor esi, esi                    ; clear esi (set it to zero)

    mov eax, 100
    mov ecx, 200                    ; MOV = copy 200 into ECX register
    mov edx, 400

    add esi, eax
    add esi, ecx
    add esi, edx
    print "Result 3 = "
    print str$(esi),13,10

  ; ---------------------------------

    pop esi                         ; restore esi

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start
Title: Re: new member introduction and advice
Post by: q12 on September 07, 2021, 09:42:14 AM
Thank you mister @hutch
Your test code, built and run successfully. Your code is both a tutorial and a test. Which is good. It is helpful to me.
I love good commented code lines !!!
My great achievement for today is that I managed, thanks to your kind help, to successfully start and run the assembler on my PC, by using the console and the textEditor. It is a great step for me.
Excelent ! And I am almost done with the console tutorials, Im on demo6. I did concentrate on them. They are very condensate and very well done !!! I really like how they were built to help the beginner. They managed to help me quite good. Because of them I started to actually write, a little bit, some very simple instructions. I also come across some errors that I comment them out and I will show the entire code I built out from those demos.
Here is your new test code built and run successfully:
-Thank you for your help!
(https://i.imgur.com/NrT9txb.jpg)
Title: Re: new member introduction and advice
Post by: q12 on September 08, 2021, 12:55:15 AM
Alright ! I managed to finish all the console demo files!I also finish your test, mister hutch.
By finish, I mean I rewrite/copied the code from right to left, manually, by hand, and made a single file that contains all these codes from all the files.
It is a compilation/gathering of all codes in one single file.
Nothing fancy, but it give me a challenge and unbelievable, I managed to make it work from the start.
I had a lot of problems with the structure of the code, where to put what, but I learned a lot this way. I am way more better than 2 days ago. It is a great advance for me. THANK YOU! I could'n done it without your help here, im refering to all those who helped me until now.
When code is assembled, I have some warnings from the last include but I imagine,  it contains the same include's as the ones before it (i didnt open it)but it is working fine after those duplicate warnings.
I commented some parts of the code that didnt worked for me in this full code page. But those codes worked by their own in their original demo files. My guess, there are some location or precedence most probably that does not allow the proper function of those specific lines to work.
Check this reply attachment for my code file:
Title: Re: new member introduction and advice
Post by: hutch-- on September 08, 2021, 01:14:55 AM
Something that you must learn is what registers you can routinely use and which registers you have to protect. Its called the "Intel Application Binary Interface" (ABI). You can routinely use EAX, ECX and EDX but the rest must have the same value on exit as they had on entry. Normally done with PUSH to save and POP to restore, it allows you to use EBX ESI and EDI. The other two, ESP and EBP should be left alone until you know a lot more about what they are used for.

Now in a simple example, if you need more than the three that can be routinely changed, you use code like the following.

push esi
push edi
; use the regs
pop edi
pop esi

Note that the pushed and pops are done in reverse order as the are pushed onto the stack memory and popped back off in reverse order.
Title: Re: new member introduction and advice
Post by: q12 on September 08, 2021, 01:54:30 AM
The operands are simple to deal with, for example: mov,add,sub,xor
But the instructions are a big unknown to me. I need a short and to the point introduction to what these instructions esi,eax,ecx,edx means and  as simple to understand them. I need a short  list of them (the easy or most common)with proper description + a general description of the entire set/register that contains them. If you please.
I'll think on an exercise to use the push and pop commands, to get more used to them.
I see in your code:  pop esi   at the end.
Thank you for the explanations on the push and pop instructions, I understand them now, but they are too new to me at this point. I need experience using them, to actually remember them and to mean something. I have a general idea about them, but at a rookie level. They are not completely new to me. So... more exercise with them and more experience. Definetly I will keep an eye on them as you told me here. Thank you.
Title: Re: new member introduction and advice
Post by: Vortex on September 08, 2021, 04:58:16 AM
Hi q12,

You can also try coding a message box application, quick and easy.
Title: Re: new member introduction and advice
Post by: q12 on September 08, 2021, 07:22:56 AM
To mister Vortex
"..try coding a message box application.."
With only the information I got from the console demo ?
I think I need a better tutorial for that. I will listen to your advice and start looking for such a tutorial.
I looked inside the tutorial folder from masm32 and I find another 3 folders, that deal with 1-how to make a dll, 2-logaritmic math stuff, 3-portable executables. They are more advanced than simple introduction to newbies like me. I could start one of those if you specifically recommend them. Your recommendation is gold to me at this point.
I know I tried in the past with assembler and windows controls and it was hell, I dont think I managed to make anything, not even a simple empty form, back then. But I dont remember the context, I think I was still in c# and tried something out of the box, I think; I really dont remember the details, only the great failure that cost me like ... a couple of weeks of reading and trying and failing and give up in the end, and follow my usual and normal routine with c#.  I think it was c#...hmmm. Totally forgotten that episode, only retain the title from it "Failure". Haha.  But now I have you guys so it's completely other context than doing everything alone like before.
I did listen to the instructions on the how to begin page,here on this forum, and from many things recommended there, I installed this ollydbg.exe program for debugging. I managed to start it and load the executable from demo console folders. It works. It is loading them and showing me another world here that I have absolutly no idea what I am looking at. I imagine it is a part of ram that program is accessing, is my best guess.Hmm. I did come across debuggers/disassembles  like this in my life, one was for cheat in games and I am aware such things exist, but I never get too familiar with them, only on the surface.
I think I need another tutorial at this point. A easy and more in depth tutorial. About any subject, I dont care, as long as it is bringing light over some notions I've seen a lot but never truly knew what are and where they come from. Hmmm... We'll see.
Title: Re: new member introduction and advice
Post by: hutch-- on September 08, 2021, 08:37:39 AM
Hi q,

The MASM32 SDK is really pointed at more experienced programmers who have worked in other languages so with C# you are at the entry level. We will help you out where we can but its a steep hill you are climbing and there are many steps to climb. Have a look at the help files in the editor as this will give you a lot more background.

For instructions (mnemonics) the best available is the Intel manuals which you get from their site. One of the members may have a simpler introduction to the instructions but I don't have any available myself.

Now as far as writing tutorials, if you are willing to write the 64 bit code I am working on to my satisfaction, I may write some 32 bit tutorials but really I don't have the time to do that.
Title: Re: new member introduction and advice
Post by: q12 on September 08, 2021, 09:08:16 AM
I understand mister hutch, don't worry. I know it is a very hard  and complicated subject.
(If you are writing something for me, I will be more than happy to try it, to copy it manually like I did until now)
But in general, you will not have to write any tutorials for anyone.
Just point me where to look, what to read, what tutorials, what steps to advance.
Like you did point me perfectly to start with the console demo codes, that really introduced me good enough.
O K , Intel manuals then... I never ever in my life touch Intel website except when I followed a recommendation these days and downloaded already the "Intel Pentium 4 Design Manual.pdf" and inside ... oh boy, haha.
I'll have to search for instructions this time - I understand and I will do exactly that.

Also, an answer for mister Vortex
I did google for a messagebox code and I found one, fix on this website:
http://masm32.com/board/index.php?topic=4015.0
it's the first code that user posted in his question.
I read it, and understood some part of it now, after the console introduction I have, I CAN SEE THINGS !
I will point out what I don't understand from that code:
push 0   ;WHEN to use these push and pop instructions and for WHAT purpose? -very noob with them
(like mister hutch suggested earlier, to look into push and pop instructions, this code serves a good example and I put it aside in my tutorials folder)
next:
mov eax,  offset MyTitle
push eax
mov eax, offset MyText
push  eax

That eax thing is bugging me greatly.  WHEN to use these instructions and for WHAT purpose? -very noob with them
You don't have to explain here anything, don't worry. Just point me where to look for the answers.
I think mister hutch give me already the path to look into Intel instructions manual, so Ill do exactly that, because it sounds logical.
If anything important to mention, please do so.

- Thank You !





Title: Re: new member introduction and advice
Post by: hutch-- on September 08, 2021, 09:15:57 AM
Here is another small test piece. If you use the manual include files, you don't use the masm32rt.inc file as it duplicates the manually included files. The masm32rt.inc is easier to use. This test piece shows somewthing basic about x86 instructions, you cannot use direct memory to memory, it must be done through a register. The reason why the ESI register is used is that the common registers, EAX ECX and EDX can be overwritten by other code where the registers that must be protected cannot be.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include\masm32rt.inc

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey               ; wait so you can see the results
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    LOCAL var1  :DWORD
    LOCAL var2  :DWORD

    push esi

    mov var1, 1234              ; load memory operand with immediate number
    mov var2, 5678

  ; add var1, var2              ; this generates an error
                                ; there is no OPCODE for memory to memory copy

  ; --------------------------------------------------
  ; adding memory operands must be done via a register
  ; --------------------------------------------------
    mov esi, var1               ; copy operand to register
    add esi, var2               ; add 2nd operand to register
    mov var1, esi               ; copy register back to operand

    print "total = "
    print str$(var1),13,10

    pop esi

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start
Title: Re: new member introduction and advice
Post by: q12 on September 08, 2021, 10:14:47 AM
Thank you for the tutorial. Very nice explained. I put it aside in my tutorial folder.
Can you find for me those Intel mnemonic books?

Title: Re: new member introduction and advice
Post by: q12 on September 08, 2021, 10:49:36 AM
"..Registers are a special working area within the processor..there are eight general-purpose registers, EAX, EBX, ECX, EDX, ESI, EDI, ESP, and EBP.  In most instances, ESP and EBP should remain unused as PowerBASIC uses them for entry and exit of procedures. This means that you have six 32-bit registers to use in your assembly code.."
I find this little nice explanation of what those registers are. Ok, so they are registers inside my CPU and not my RAM as i originally guessed.
Why are so many and when to use one or another? That's my next question.

update1: I've made an account into www..intel.com
update2: I find this page:
https://software.intel.com/content/www/us/en/develop/download/intel-64-and-ia-32-architectures-sdm-combined-volumes-1-2a-2b-2c-2d-3a-3b-3c-3d-and-4.html
and downloaded this cute and short introduction pdf that has 4778 pages and it will take me 10 years + to finish reading it fully.
And is also having 4 Volumes in one pdf. I seriously downloaded it and now im looking in it... but I see nothing that can help me yet ... hmm, maybe I will get lucky.. in 10 years or so. Haha, I'm laughing with tears. Im starting to search things in it though... I hope is the right book (with 4 Volumes in it) lol.  - Please confirm if it's the right thing to OPEN and read or not. Since I did it by instinct until now.
Title: Re: new member introduction and advice
Post by: hutch-- on September 08, 2021, 01:13:43 PM
Intel provide a number of formats, 4 separate manuals or all 4 combined. Either will do and look for the"Instructions" manual. There are a hell of a lot of them, high hundreds but the ones you want now are the simple integer instructions, MOV ADD SUB SHL(R) ROL ROR CMP XOR OR etc .....

I don't have one for you but there have been simplified collections that are much easier to follow. The Intel manuals are by far the best but you get swamped with information that is not always easy to understand.

Once you get the swing of the ordinary integer instructions, we will show you how to read and write "complex addressing mode" that looks like this.

mov eax, [ecx+edx+64]

Among other things, its used for arrays and is a critically important technique for addressing memory.

Here is one link that may be a bit easier to work with.

https://www.felixcloutier.com/x86/add (https://www.felixcloutier.com/x86/add)
Title: Re: new member introduction and advice
Post by: q12 on September 08, 2021, 02:24:35 PM
Thank you mister hutch !
So... im not crazy, it is a LOT of information there. Hmmm. I thought I am the UN-lucky one. Since you didnt say anything (bad) about my Intel link, I consider that I find the right book !!!
As I said, I started to actually read through the book (of death), I actually jumped directly to what is most critical for my knowledge : GPR (general purpose registers) and I understand their clasifications now, 8,16,32 and (the newest) 64 bytes.  They kind of put little bits of information in 1 chapter and then to another chapter a couple chapters down. SO I had to (mindlessly) scroll down, and lucky me, I found in a couple of chapters, mentions of this GPR that I am most interested into. Still not there yet, since they explain the locations and dimensions, A LOT, but not really what is important (to me), which is... what are they good for? I'm not sure if I ask the right question now after reading all of that... As a general idea, the GPR are used for aritmetic and logical operations... but... in practice !!! I can not see the practical side of them, yet. I'll hammer this book these days as much as I can and as far I can go. If Im getting this basic thing, oh boy... GPR is basic right? is it an advanced thing? I dont know. You tell me.
I also started to collect these chapters into a single text file. And after that, Ill have to condense again, what I just collected. Hopefully, that's the plan. It's a crazy lecture, I tell you that. What is interesting though, over all that terminology mambo-jambo, I do understand the big idea, and in a sense, it is kind of easy to read... or maybe I am too purpose driven right now, thats why I can fly over things more easily. That must be it... Anyway... Ill update you about my evolution (hopefully).

Update1:
I think I just find your thing you wanted to teach me in your example:
"mov eax, [ecx+edx+64]"
3.7.5 Specifying an Offset  (at page 86)
Figure 3-11. Offset (or Effective Address) Computation
Base    Index     Scale     Displacement
[eax] + [eax    *   1]   +  [8bit]
Title: Re: new member introduction and advice
Post by: q12 on September 08, 2021, 03:29:54 PM
I need clarification:
Intel say: "

MOV     Move data between general-purpose registers; move data between memory and generalpurpose or segment registers; move immediates to general-purpose registers.

- What  "memory" is he talking about? The RAM memory? Or some other type of memory? Is CPU having a memory? I am inclined to think he is refering to CPU memory. 


5.1.8 String Instructions
The string instructions operate on strings of bytes, allowing them to be moved to and from memory

- Again, What  "memory" is he talking about?

From my general knowledge:
A CPU is having only registers addresses.
A RAM is having only memory addresses.
Is this information I know complete ? Or there is something more?
Title: Re: new member introduction and advice
Post by: TouEnMasm on September 08, 2021, 05:22:40 PM
Intel speak of general memory who can be access with a pointer on it.
He can be heap memory or other type ,no matter.
you put the pointer on a register.
Quote
invoke HeapAlloc,HandleHeap,NULL,1000h
mov ebx,eax
mov edx,[ebx]     ;load a register with a  memory location
other type
Quote
.data
roudou dword 0
.code
mov ebx,offset roudou
mov byte ptr [ebx],1                         ;first byte of dword roudou begin one
Title: Re: new member introduction and advice
Post by: mineiro on September 08, 2021, 09:12:25 PM
Inside processors exist memory.
Registers are one specific type of memory inside processor.

To access the contents of an address in RAM memory, a processor need lock bus data/control/address, access that data, and unlock bus. This spends time.
To increase this access time, enginers created inside a processor a cache memory. (L1,L2,L3). This cache memory is not enough being necessary RAM memory. Access to L1 cache is quickly, L2 a silver medal, L3 a bronze medal, followed by RAM competitors. Intention is that a bit of memory is inside processor instead of outside.

Some microcontrolers call "registers" specific memory location in RAM memory. We can label eax register the first memory location and they size is 4 bytes.

If I move number 4 to eax register. I'm moving what? A memory address or number 4 (immediate)? Who define this are us, programmers.

When dealing with X86 processors we need pay attention to move data between memory locations. In better words, I got one data from a memory location, moved that data to a register, and moved that data from a register to other memory location.
When you read Intel manual you will see that most instructions can deal with register to register, register to memory, memory to register. What about memory to memory!?
Title: Re: new member introduction and advice
Post by: q12 on September 09, 2021, 01:25:49 AM
Thank you mister @mineiro
Excelent explanation. In fact, last night until morning and right after I jumped from bed, I google the shit out of this problem.
And I find some very interesting answers that also confirms what you just said here.
This is my conclusion after reading everything:
Does a CPU have its own RAM?
The short answer: YES
It is a form of memory that is called Register.
It is very small size, starting with 1bit then 1byte(8bits) to 16,32 or 64bytes.
They are the fastest ram implementation in a computer. They live inside a CPU.
Some are adresable (read&write), some are read only or write only.
They hold immediate data, adresses, and pointers.
It is SRAM implementation (static ram and is the fastest and easy to build)

then you said:
Quote
...When you read Intel manual you will see that most instructions can deal with register to register, register to memory, memory to register....
Then this distinction between register and memory is a bit confusing. It should be the same thing.
The memory they are mentioning can be 2 things: 1-a memory in RAM OR 2-a register that is used as it would be a memory.
Because a register have multiple significations, they are "specific" by saying it is a memory. But they should name them as registerMemory (for when it is used like that). This is my personal interpretation after a ton of reading.
Thank you for your answer !
Title: Re: new member introduction and advice
Post by: mineiro on September 09, 2021, 02:08:34 AM
hello sir q12;
A processor operates at certain clock pulses by a quartz cristal (frequency, hertz). Processors operates at so much higher frequencies, while RAM memory at not so high. So, I suppose register and memory can be differenciated. To a begginer the cache memory is invisible, so, if that confuse you, forgot that.
The term memory told in manual can be viewed as a data source. Can be RAM memory, ROM memory, a hard disk, a stick, ... .  What is important is, to you read/write to a hard disk, or a RAM memory you will use same processor instruction. The initial concept of file in linux as an example is "everything is a file". I prefer change to "everything is a data".

You told about PIC. You perceived that a lot of instructions only changed name (opcode/mnemonic). PIC have flow instructions (compare, jump conditional/inconditional), arithmetic (add,sub,mul,div), boolean (and,or,not,xor), ... . One big difference is that PIC is RISC, while X86 is CISC. Well, if you disassemble a code, PIC hexadecimal dump of each instruction (opcode) have 2 bytes, maybe 4 bytes, forgot now. If you look to x86, one instruction can have 1 byte, while other 2 bytes, and others N bytes, it's a zoo. I suppose that PIC use specific memory (RAM) address as registers. Good and bad, if you write to a specific memory location is the same as write in a register.
Title: Re: new member introduction and advice
Post by: q12 on September 09, 2021, 02:25:50 AM
So far, this is how I understand the mechanism:
for example:
    mov eax,100     ;copy 100 into eax register
    mov ecx,250     ;copy 250 into ecx register
    add ecx, eax

inject an immediate value (of 100) into eax (an Accumulator for operands and results data)
inject an immediate value (of 250) into ecx (a Counter for string and loop operations)
add these 2 registers and the result store it into ecx (because is the left operator) and also it is (a Counter for string and loop operations)?
My biggest issue, is WHY and WHEN to use eax, or ecx ? What is the logic for using 1 register or another?
What is his reason to choose these 2 registers and not other ones, like for example ebx and edx ? It is because the other registers are all pointer registers? By the look of it. Or it's an arbitrary reason? Choose whatever you want, it doesnt matter? (type of logic)
I observe that only eax and ecx are NOT pointers. But the rest ARE pointers.
This detail is absolutely vital?
- Can we can treat every register (the first 6 of them) as general good for anything?
Or
- Can we treat them for their specific type of operation that is assigned to?

The following is a summary of special uses of general-purpose registers:
* EAX - Accumulator for operands and results data
* EBX - Pointer to data in the DS segment
* ECX - Counter for string and loop operations
* EDX - I/O pointer
* ESI - Pointer to data in the segment pointed to by the DS register; source pointer for string operations
* EDI - Pointer to data (or destination) in the segment pointed to by the ES register; destination pointer for string operations
the last 2 are not to be touched:
* ESP - Stack pointer (in the SS segment)
* EBP - Pointer to data on the stack (in the SS segment)

Thank you !
Title: Re: new member introduction and advice
Post by: FORTRANS on September 09, 2021, 06:49:23 AM
Quote from: q12 on September 09, 2021, 02:25:50 AM
My biggest issue, is WHY and WHEN to use eax, or ecx ? What is the logic for using 1 register or another?

   My suggestion to you is to download:

Intel Architecture Software Developer's Manual Vol 1 Basic Architecture
Intel Architecture Software Developer's Manual Vol 2 Instruction Set Reference

Or the AMD equivalent.  To start off I would recommend a Google search on;

386INTEL.PDF

That is the 1986 version.  A bit simpler version than the more current versions.

Quote
What is his reason to choose these 2 registers and not other ones, like for example ebx and edx ? It is because the other registers are all pointer registers? By the look of it. Or it's an arbitrary reason? Choose whatever you want, it doesnt matter? (type of logic)

   Looking up an instruction in the reference will show what registers a given
instruction can use.

Quote
I observe that only eax and ecx are NOT pointers. But the rest ARE pointers.

   EAX and ECX can be used to address memory, or as you say be a pointer.

Quote
This detail is absolutely vital?
- Can we can treat every register (the first 6 of them) as general good for anything?
Or
- Can we treat them for their specific type of operation that is assigned to?

   EAX, EBX, ECX, EDX, EDI, ESI, and EBP can be used as "general purpose"
registers for instructions like MOV or ADD.

   EAX is used for MULtiply, DIVide, and string source or destination.  and a number
of "special" instructions (CWD, IN, OUT, ...).

   BX in 16-bit code was a base pointer.  OBE.

   ECX is used as a counter in LOOP and string instructions.

   EDX is used in IN, OUT, MUL, and DIV and some special instructions.

   EDI and ESI have defined roles in string instructions.

   BP in 16-bit code was a base pointer, either to access variable on the stack,
or with a segment override for data.

HTH,

Steve N.
Title: Re: new member introduction and advice
Post by: q12 on September 09, 2021, 07:27:00 PM
to mister FORTRANS
I am reading: INTEL 80386 PROGRAMMER'S REFERENCE MANUAL 1986, as you recommended.
It is better explained !
I trust old books more than anything. And I trust your recommendation.
Thank you.

I'm also starting to understand that assembler is like Lego. At least is a very young impression. Im still not there yet, but it starts to formulate something in my mind, on how to use the instructions and why. A little bit. All these ideas after the copying exercise and reading. They sum up. My impression is that you build, like with bricks, each line of code, literally. It is a very literal language in a sense. Again, one of my first impressions.
I will have to make a series of exercises to actually start thinking (in assembler) when coding. As little as I understand it, with its bricks.

I also find the answer to my question:
"
My biggest issue, is WHY and WHEN to use eax, or ecx ?
What is the logic for using 1 register or another?
Or it's an arbitrary reason? Choose whatever you want, it doesnt matter? (type of logic)
"
From INTEL 80386 :
2.3.1 General Registers
The general registers of the 80386 are the 32-bit registers EAX, EBX, ECX,
EDX, EBP, ESP, ESI, and EDI. These registers are used interchangeably to
contain the operands of logical and arithmetic operations. They may also be
used interchangeably for operands of address computations (except that ESP
cannot be used as an index operand).

My conclusion:
So these registers are "general" also in the sense to use them and change between them as you please when coding !
They are more like some temporary variables. This was the answer I was looking. I did get the answer, one way or another.
Title: Re: new member introduction and advice
Post by: hutch-- on September 09, 2021, 08:24:10 PM
Beware of old x86 info, in Win32 you can use all of the 32 bit registers, you just have to know which to protect and which you can freely modify. I mentioned it before, the Intel Application Binary Interface. Where you MUST use specific registers is with instructions that require it, MOVS, STOS and a few others. They use ESI and EDI. Some instructions only work with EAX. You look these up in the Intel instruction manual.

Until you know enough do not try and use EBP and ESP as they are used to construct stack frames.
Title: Re: new member introduction and advice
Post by: q12 on September 09, 2021, 10:00:04 PM
I understand mister hutch.
So, I should concentrate on the first 4 of them: EAX, EBX, ECX,EDX,
and the last 4 (EBP, ESP, ESI, and EDI) to not touch until I will be more experienced. Very good advice then.
It is exactly what I want to know- what to do and what not to do. That's how I learn.
Thank you again.
Title: Re: new member introduction and advice
Post by: hutch-- on September 09, 2021, 11:09:43 PM
No, you are making unsound assumptions. Freely use EAX ECX and EDX but preserve EBX ESI and EDI as I showed you. Leave ESP and EBP alone as they provide the stack frame.
Title: Re: new member introduction and advice
Post by: q12 on September 10, 2021, 03:18:43 AM
I think I understand you now.
So only these 3: EAX ECX and EDX are OK to use.
EBX ESI and EDI to protect them as you put it. So not to touch.
ESP and EBP to not touch them ever.
Correct?

QuoteNo, you are making unsound assumptions.
Also, I am unable to make unsound assumptions. I am only trying (my best) to understand what is going on.
I only follow the data I can see, and that was the data I could gather by reading from all these books.
And of course I can not retain EVERYTHING. Some things may slip. But they are honest mistakes.
Don't interpret me as doing anything bad voliciously.
I am telling you the truth, either you believe me or not.
And also I am trying my best. Do you know how hard is this for me as a beginner? I'm telling you, it is hard.
If I didnt complain until now, now  I will.
Title: Re: new member introduction and advice
Post by: Vortex on September 10, 2021, 04:19:53 AM
Hi q12,

Here is a message box example for you :

include \masm32\include\masm32rt.inc

.data

message1  db 'This is test 1',0
message2  db 'Another test',0
caption1  db 'Hello',0
caption2  db 'Buenos dias',0

.code

start:

    invoke  MessageBox,0,ADDR message1,ADDR caption1,MB_OK

    push    MB_OK
    push    OFFSET caption2
    push    OFFSET message2
    push    0

    call    MessageBox

    invoke ExitProcess,0

END start

You can directly push the location \ OFFSET of a string to the stack. No need of the mov eax,OFFSET message1 and push eax pair.

Are OFFSET and ADDR the same thing?

https://masm32.com/board/index.php?topic=4994.0

The MessageBox API :

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox

Iczelion's tutorials :

https://masm32.com/download/icztutes.exe

https://masm32.com/website/iczelion/iczelion.zip

QuoteTutorial 2: MessageBox

Iczelion's tutorial set is very good to learn assembly language for Windows programming. It also covers coding GUI like windows with controls and dialog boxes.

Attached is the message box sample.
Title: Re: new member introduction and advice
Post by: six_L on September 10, 2021, 04:34:35 AM
Hi q12,
Welcome to here.
If you don't understand  some codes, try to use x64dbg(http://x64dbg.com (http://x64dbg.com)), runnig the codes step by step, x64dbg will show you more informations.

Regards.
Title: Re: new member introduction and advice
Post by: Vortex on September 10, 2021, 04:37:01 AM
Hi q12,

Quote
So only these 3: EAX ECX and EDX are OK to use.
EBX ESI and EDI to protect them as you put it. So not to touch.
ESP and EBP to not touch them ever.

eax,ecx and edx are general purpose registers. They are OK to use.

ebx,esi,edi and ebp can be modified with the condition that you preserve their original values before exiting a procedure. They are non-volatile registers :
Quote
Callee-saved (non-volatile) registers
The other registers are used to hold long-lived values (non-volatile), that should be preserved across calls.

In other words, when the caller makes a procedure call, it can expect that those registers will hold the same value after the callee returns.

Thus, making it the callee's responsibility to both save (push at the beginning) and restore (pop accordingly) them before returning to the caller. As in the previous case, this practice should only be done on registers that the callee changes.

https://en.wikipedia.org/wiki/X86_calling_conventions

The value of eax,ecx,edx are destroyed across Windows API calls. This is not the case while handling esi,edi,ebx and ebp, the non-volatile registers.

esp should not be modified as it's responsibility is to address the stack frame.
Title: Re: new member introduction and advice
Post by: avcaballero on September 10, 2021, 06:00:27 AM
Here my thought. Don't expect to learn everything in one day, just take it easy. Don't do everything in the academic way, just do it to work and keep on learning in better ways.
Title: Re: new member introduction and advice
Post by: q12 on September 10, 2021, 06:25:27 AM
Hello Vortex
I tested your console code and also download it from the attachment (which I was not familiar in the very begining).
I keep getting a black console window poping out when I execute the file. This happens only in C:/ drive. In D:/ drive it is not appearing, but also the compiler is not making anything in this last drive. Works Only in C:/
I think I understand your pages that you linked, for the OFFSET keyword you used in the code and also for the MB_OK.
The Iczelion's tutorials are looking very interesting !
I will start them. Most probably by simply copy their code to get used with things.
{
I'll have to make the effort of writing my own programs, dealing with simple stuff like aritmetic operators and booleans for the momment
It was in plan, until the new tutorials arrived from you. But it is very good !
New tutorials are always welcomed ! The best thing I can do, is to copy things, haha.
}

Hello six_L
Very memorable face... , also very nice x64dbg software. I download it, and unzip it and run it.
I run a very simple console program from those demo in masm32 folder. Just to test it and it works.
I love it's user interface with all it's colorfull and good taste icons in it!!!
But... is still over my head. I did come across such debuggers in my life so I am somewhat familiar with their existence.
But im not pertinent to say I can use them.
Thank you, I put it aside for future use, when I will be more sure how to use it.

At Vortex again:
Thank you very much for the complete explanation on these general registers !
It REALLY helped me understand them more clearly now.
Also you give me a nice hint for what are good for, the Push(save) and Pop(load) opcodes.
Now we understand eachother!!! Keep explaining like this and we are lift off sooner than expected.

to caballero:
Im doing my best!  ...and it is slow and hard.
Im not rushed to go anywhere so im doing it at my normal pace.

Thank you all!
Title: Re: new member introduction and advice
Post by: Vortex on September 10, 2021, 06:41:52 AM
Hi q12,

You are welcome. The message box example is not console application, it's a GUI sample.

A loop sample ( console application ) and preserving the value of ebx :

include \masm32\include\masm32rt.inc

.data

s1          db 'This is the first loop example',13,10,0
s2          db 'This is the second loop sample',13,10,0

.code

start:

    call    myproc
    call    sample
   
    invoke  ExitProcess,0

myproc PROC uses ebx

; The uses statement will take care of ebx

    mov     ebx,3

loop1:

    invoke  StdOut,ADDR s1
    dec     ebx
    jnz     loop1

    ret

myproc ENDP


sample PROC

    push    ebx
    mov     ebx,4

mylabel:

    invoke  StdOut,ADDR s2
    dec     ebx
    jnz     mylabel

    pop     ebx
    ret

sample ENDP

END start



Title: Re: new member introduction and advice
Post by: avcaballero on September 10, 2021, 07:08:13 AM
Hi, q12, here's a starting point that you may find useful... or not, who knows  :greensml:

http://abreojosensamblador.epizy.com/?Tarea=6&SubTarea=2&Lang=1
Title: Re: new member introduction and advice
Post by: mineiro on September 10, 2021, 07:18:11 AM

include \masm32\include\masm32rt.inc
;perceive call/ret pairs
;perceive push/pop pairs
.code
start:
    call trash_registers        ;save manually registers contents
    call trash_registers2       ;uses masm automation
    mov eax,0
    call dont_trash_eax
    invoke  ExitProcess,EAX     ;exit this process returning 0 (eax) as OK information
   
trash_registers proc
    push ebx        ;save register contents in stack
    push edi        ;do this at start of your procedure/function/routine
    push esi

    mov ebx,0       ;trash registers contents
    mov edi,1
    mov esi,2

    pop esi         ;restore them before ret or exit, note, reverse order
    pop edi
    pop ebx
    ret             ;return one instruction after who called us
trash_registers endp

trash_registers2 proc uses ebx edi esi          ;"uses" will save (push) and restore (pop) as example above
    mov ebx,0       ;trash registers contents
    mov edi,1
    mov esi,2
    ret             ;return one instruction after who called us
trash_registers2 endp

dont_trash_eax proc uses eax                    ;"uses" will save and restore only eax
    mov eax,2           ;trash eax
    ret
dont_trash_eax endp

END start           ;our code begins at "start" label
Title: Re: new member introduction and advice
Post by: q12 on September 10, 2021, 07:31:30 AM
Quote from: Vortex on September 10, 2021, 06:41:52 AM
You are welcome. The message box example is not console application, it's a GUI sample.
You really don't trust my word.
The windows form (messagebox) is opening fine in both drives, c:\ and d:\
But that Big Black Console window !
Here is what it does while run from c:\ drive. It does not appear when it is run from d:\ drive.
That black console window should not appear at all, indiferent of the drives it is run ! It is what Im saying.
I am unsure if this is normal, that it should suppose to happen or not.
But, its a little detail that is really non important.

(https://i.imgur.com/aOGLop5.jpg)
Title: Re: new member introduction and advice
Post by: jj2007 on September 10, 2021, 08:48:20 AM
In case you are using qEditor: there is "Build all" and "Console build all". Check the difference.
Title: Re: new member introduction and advice
Post by: hutch-- on September 10, 2021, 09:49:46 AM
 :biggrin:

I think I understand you now.
So only these 3: EAX ECX and EDX are OK to use.
EBX ESI and EDI to protect them as you put it. So not to touch.
ESP and EBP to not touch them ever.
Correct?

No, you are AGAIN making unsound assumptions.

EBX ESI and EDI to protect them as you put it. So not to touch.

You use EBX, ESI and EDI on a needs basis using the PUSH POP pair. Much later you can use EBP and ESP once you understand what they do.

You get your ear chewed because you MUST GET THIS RIGHT, make incorrect assumptions now and it will be a lot harder to fix it later.
Title: Re: new member introduction and advice
Post by: q12 on September 10, 2021, 10:09:13 AM
to mister hutch
I clarified the general registers already with mister Vortex (after talking with you)
Here is how I saved the last clarification:

EAX ECX and EDX     OK to use at will. They are volatile registers meaning, their value is destroyed across Windows API calls.
EBX ESI EDI and EBP Need protection, they can be modified with the condition that you preserve their original values before exiting a procedure. They are non-volatile registers.
                    "You save (push at the beginning) and restore (pop accordingly) them, before returning to the caller." -
ESP                 should not be modified as it's responsibility is to address the stack frame
Title: Re: new member introduction and advice
Post by: q12 on September 10, 2021, 04:07:27 PM
I started to write some code myself, looking and not looking at the samples codes.
I made a couple of test-code that speedup my understanding of these basic opcodes and sintax.
I concentrated on: mov, add and sub opcodes
LOCAL var1  :DWORD    from 1 sample code did helped me understand the mechanism a bit more faster.
I watched some video tutorials and they helped me speed up understanding.
So
I jumped to mul operand and I understand now how is working. And I have no problems with it's code.
I jumped to div operand and I understand now how is working. But I have a problem with it's code!!! A windows error appear when it tries to execute the div statement.
I've made some basic test-codes for each operand I am using. Mostly to get used to it and with the assembler syntax.
Check attachment of this message, for the div code. Remember, I did it as a test code. That's why is looking like an experimental code.
Here is the windows error that I get only from div operator:
(https://i.imgur.com/yM9JTUf.jpg)
Title: Re: new member introduction and advice
Post by: hutch-- on September 10, 2021, 04:22:38 PM
You keep modifying the advice you are given, EBP (the base pointer) is used in conjunction with ESP (that stack pointer) to provide the stack frame for normal procedures. Try using EBP in a normal procedure and it will most probably CRASH on you. Stick to the normal 3, EAX ECX & EDX and with protecting the non volatile registers, ESI EDI & EBX.

Do it the right way and you will write reliable code, do it any other way and get used to unreliable crashes. You can write a massive amount of code with the 6 available registers, it is only specialised code with no stack frame that does otherwise.
Title: Re: new member introduction and advice
Post by: mineiro on September 10, 2021, 07:36:23 PM
build as console


include \masm32\include\masm32rt.inc

.data
var5 dd 1 ;INITIALIZED data, GLOBAL scope, all code can play with this

.data?
var6 dd ? ;UNITIALIZED data, GLOBAL scope, all code can play with this
;we need initialize this variable in our code before use this

.code
start:
call main
exit


main proc uses ebx esi edi
LOCAL var1:DWORD ;UNITIALIZED data, LOCAL scope, can be played only inside this proc
;each time we run a program this variable will have different values
;so we need first initialize this variable
LOCAL var2:DWORD
LOCAL quotient:DWORD
LOCAL remainder:DWORD

mov var1,9 ;initializing these local variables
mov var2,2

print chr$("dividend = ")
print str$(var1)
print chr$(13,10)

print chr$("divisor = ")
print str$(var2)
print chr$(13,10)

mov edx,0 ;edx:eax pair in mul/div instructions
;edx value at this point can be anything, so lets zero it
mov eax, var1 ;0:9
mov ecx, var2 ;09 / 2 = ?
div ecx             ;divide edx:eax by ecx and store quotient in eax and remainder in edx
   
;eax,edx,ecx are volatile registers, so, if I like to print their contents, the next
;time that I will print again values in these registers will probably get destroyed
;so I need save them before print
   
mov quotient,eax
mov remainder,edx
   
print chr$("quotient = ") ;this print probably destroyed some volatile registers
print str$(quotient) ;but we saved before that contents in some variables
print chr$(13,10) ;print CR LF (Carriage return, Line feed)
   
print chr$("remainder = ")
print str$(remainder)
print chr$(13,10)

ret
main endp

end start
Title: Re: new member introduction and advice
Post by: TouEnMasm on September 10, 2021, 11:34:11 PM

The div operation need an edx NULL if it is a dword operation ( other way edx:eax = QWORD)
Quote
Divides unsigned the value in the AX, DX:AX, EDX:EAX, or RDX:RAX registers (dividend) by the source operand
   (divisor) and stores the result in the AX (AH:AL), DX:AX, EDX:EAX, or RDX:RAX registers. The source operand can
   be a general-purpose register or a memory location. The action of this instruction depends on the operand size
   (dividend/divisor). Division using 64-bit operand is available only in 64-bit mode.
   Non-integral results are truncated (chopped) towards 0. The remainder is always less than the divisor in magni-
   tude. Overflow is indicated with the #DE (divide error) exception rather than with the CF flag.
   In 64-bit mode, the instruction's default operation size is 32 bits. Use of the REX.R prefix permits access to addi-
   tional registers (R8-R15). Use of the REX.W prefix promotes operation to 64 bits. In 64-bit mode when REX.W is
   applied, the instruction divides the unsigned value in RDX:RAX by the source operand and stores the quotient in
   RAX, the remainder in RDX.
   See the summary chart at the beginning of this section for encoding data and limits. See Table 3-15.
   Table 3-15. DIV Action
   Maximum
   Operand Size                         Dividend          Divisor         Quotient            Remainder             Quotient
   Word/byte                            AX                r/m8            AL                  AH                    255
   Doubleword/word                      DX:AX             r/m16           AX                  DX                    65,535
   Quadword/doubleword                  EDX:EAX           r/m32           EAX                 EDX                   232 - 1
   Doublequadword/                      RDX:RAX           r/m64           RAX                 RDX                   264 - 1
   quadword
Title: Re: new member introduction and advice
Post by: q12 on September 11, 2021, 04:59:00 AM
Mister mineiro, just perfect code, my hat off.
Fantastic working code and most of all, explanations per each line. Just brilliant !
I wish every tutorial to be like you just created here with your code and comments.
Title: Re: new member introduction and advice
Post by: q12 on September 11, 2021, 05:18:07 AM
Can't I delete this post?
Title: Re: new member introduction and advice
Post by: q12 on September 11, 2021, 05:20:03 AM
Can anyone make an educated guess what the correspondent in masm32 will be for this:
"f              Register file address (0x00 to 0x7F)"
It's very important for me to nail this thing. For me it looks like a variable (var1) or another register (like EBX).
But I want to be sure, by asking you.
Please see the image table I made here: https://i.imgur.com/2AqsZe1.jpg (https://i.imgur.com/2AqsZe1.jpg)
or check the attachment for the same image file.
Title: Re: new member introduction and advice
Post by: mineiro on September 11, 2021, 07:55:40 AM
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.
Title: Re: new member introduction and advice
Post by: 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 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.
Title: Re: new member introduction and advice
Post by: mineiro on September 11, 2021, 08:19:52 PM
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
Title: Re: new member introduction and advice
Post by: jj2007 on September 11, 2021, 10:49:11 PM
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:
Title: Re: new member introduction and advice
Post by: q12 on September 12, 2021, 03:44:05 AM
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 (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.
Title: Re: new member introduction and advice
Post by: Vortex on September 12, 2021, 06:25:21 PM
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.
Title: Re: new member introduction and advice
Post by: q12 on September 12, 2021, 09:09:39 PM
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 !
Title: Re: new member introduction and advice
Post by: jj2007 on September 13, 2021, 04:57:24 AM
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
Title: Re: new member introduction and advice
Post by: Vortex on September 13, 2021, 05:49:57 AM
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.
Title: Re: new member introduction and advice
Post by: q12 on September 13, 2021, 10:39:23 AM
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 (https://i.imgur.com/bYm9GtK.jpg)
You give me this link: https://www.hobbyprojects.com/pic_tutorials/tutorial2.html (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 !
Title: Re: new member introduction and advice
Post by: 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:
Title: Re: new member introduction and advice
Post by: jj2007 on September 13, 2021, 07:12:18 PM
Quote from: q12 on September 13, 2021, 11:22:23 AMI am guessing big time

RTFM
Title: Re: new member introduction and advice
Post by: mineiro on September 13, 2021, 08:47:54 PM
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.
Title: Re: new member introduction and advice
Post by: daydreamer on September 13, 2021, 10:52:24 PM
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
Title: Re: new member introduction and advice
Post by: q12 on September 14, 2021, 08:00:51 AM
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!
---
(https://i.imgur.com/2mRJrqQ.jpg)
Title: Re: new member introduction and advice
Post by: mineiro on September 14, 2021, 08:58:08 AM
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.
Title: Re: new member introduction and advice
Post by: hutch-- on September 14, 2021, 09:59:35 AM
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
Title: Re: new member introduction and advice
Post by: q12 on September 14, 2021, 02:50:16 PM
To hutch: - Thank you for your useful information !
Title: Re: new member introduction and advice
Post by: q12 on September 14, 2021, 04:24:42 PM
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.
Title: Re: new member introduction and advice
Post by: jj2007 on September 14, 2021, 05:42:53 PM
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:
Title: Re: new member introduction and advice
Post by: mineiro on September 14, 2021, 09:47:17 PM

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                   
Title: Re: new member introduction and advice
Post by: q12 on September 15, 2021, 08:45:16 AM
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 (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)
Title: Re: new member introduction and advice
Post by: q12 on September 15, 2021, 02:13:50 PM
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.
Title: Re: new member introduction and advice
Post by: daydreamer on September 15, 2021, 07:56:36 PM
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
Title: Re: new member introduction and advice
Post by: mineiro on September 15, 2021, 08:02:36 PM
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
Title: Re: new member introduction and advice
Post by: q12 on September 15, 2021, 10:35:27 PM
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 (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/ (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 (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.


Title: Re: new member introduction and advice
Post by: daydreamer on September 15, 2021, 11:14:22 PM
https://education.ti.com/en/products/computer-software/ti-connect-ce-sw (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
Title: Re: new member introduction and advice
Post by: q12 on September 15, 2021, 11:37:40 PM
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 (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.
Title: Re: new member introduction and advice
Post by: mineiro on September 15, 2021, 11:47:19 PM
Bin files are raw data, like rom files, like hex files, ... .
Rename pic.bin to pic.hex.
Title: Re: new member introduction and advice
Post by: q12 on September 16, 2021, 12:19:46 AM
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 :
(https://i.imgur.com/3lRRhDh.jpg)
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.
Title: Re: new member introduction and advice
Post by: q12 on September 16, 2021, 12:54:20 AM
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.
Title: Re: new member introduction and advice
Post by: mineiro on September 16, 2021, 02:44:38 AM
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.
Title: Re: new member introduction and advice
Post by: q12 on September 16, 2021, 10:14:51 AM
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.


Title: Re: new member introduction and advice
Post by: q12 on September 16, 2021, 10:30:09 AM
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:
(http://masm32.com/board/Themes/default/images/bbc/img.gif) >> https://www.deviantart.com/q12a/art/q20210904-EasyPIC-all-registers-890812289 (https://www.deviantart.com/q12a/art/q20210904-EasyPIC-all-registers-890812289)
Title: Re: new member introduction and advice
Post by: mineiro on September 16, 2021, 08:06:36 PM
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.
Title: Re: new member introduction and advice
Post by: TimoVJL on September 16, 2021, 08:35:30 PM
Is this useful for testing ?
PICSimLab - Prog. IC Simulator Lab. (https://sourceforge.net/projects/picsim/)

Link collction:
http://www.picemulator.com/links.html
Title: Re: new member introduction and advice
Post by: q12 on September 16, 2021, 09:33:42 PM
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 (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.
Title: Re: new member introduction and advice
Post by: daydreamer on September 16, 2021, 10:54:49 PM
 :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:
Title: Re: new member introduction and advice
Post by: mineiro on September 17, 2021, 06:53:11 AM
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.
Title: Re: new member introduction and advice
Post by: q12 on September 20, 2021, 12:46:48 AM
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?
Title: Re: new member introduction and advice
Post by: mineiro on September 20, 2021, 09:31:34 AM
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.
Title: Re: new member introduction and advice
Post by: q12 on September 20, 2021, 10:41:51 AM
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.



Title: Re: new member introduction and advice
Post by: q12 on September 20, 2021, 11:36:24 AM
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 (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
Title: Re: new member introduction and advice
Post by: mineiro on September 20, 2021, 09:12:11 PM
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
Title: Re: new member introduction and advice
Post by: daydreamer on September 20, 2021, 11:51:49 PM
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
Title: Re: new member introduction and advice
Post by: q12 on September 21, 2021, 02:31:56 PM
Good day, mister mineiro
QuoteIf you look that file "p12f508.inc" you will see a lot of EQUates like GPIO,OSCCAL as example.
EQU might mean EQUAL as well. It has a bit more sense in my head. FINE EQUAL 0x01
I think I understand this EQU thing now:
I imagine, that it may be a true CONSTANT. I've never used constants in my programming life, and what examples I've seen so far, they were mindless and meaningless.
But now, reading all this... I read your explanations, then I look in both Intel books, then I check 12f508.inc and indeed is full of EQU in it (I dont remember checking this file inside before)
I believe, that assignment name that we give: STATUS,GPIO,OSCCAL and your FINE example, they refer to -imutable- or -unchangeble- values  H'0001' to H'0007' that are fixed registers inside the processor or this PIC ram-memory-register.
Now, and only now, a constant has meaning for me ! That is something. Correct me if im wrong, of course.
After looking in p12f508.inc, what I trully dont understand is why W,INDF,C,PS0   EQU H'0000'. The same goes for those who EQU H'0001' up to EQU H'0007'
I understand perfectly they mean for ex: [NAME of] W EQUAL [BIT] H'0000' but the same goes for the other values.
What (code) is splitting them into registers to fit each specific register? Starting each from 0 to 7. I bet if you change the order of these lines, your compiler will shit itself with errors.
I would love to see the code that split and assign all these bits to their respective registers.
Or at least an interpretation (from your part) of that code, if the real code is buried inside compiler.

QuoteI think that "__config" line in source code is creating a binary number (byte) by seting/reseting some specific bits in 8 bits field.
I totally think that as well, and I did come across other codes (in my life) that were declaring __config as a set of bits something like b'01011010' for example.

QuoteSo, "__config" line used AND (&) operator. You need probably check the meaning (equ) of _MCLRE_ON, _CP_OFF , _WDT_OFF , _IntRC_OSC
So this is homework for me, right? Haha, Yes, I like it.
By looking inside 12F508 datasheet (or manual), I find the Configuration Register that has 11bits in length but only the first 5 bits are active.
The rest, from bit 5 to bit 11, are NOT-implemented (gray out).
Image: https://i.imgur.com/0u5aI8E.jpg (https://i.imgur.com/0u5aI8E.jpg)
This is the part that I trully love about PIC's (and they made it so hard to see it with meaningless explanations of some weird stuff that is meant to derail you)
Every BIT counts! Haha. Meaning, you can actually count bits and they mean something both in real chip and in your code.
If we look on the table for Configuration Register inside datasheet, we can see the bit values for EVERY possible combination of configuration bits.
So, in our code, and I know this part very well, if let's say for example we have:
                       __config _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC
then it means:__config          1                    1                   0                   10
and you can write it as: __config B'11010' and it means the same damn thing as  __config _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC
But using only bit codes becomes very encripted, very quickly. It is very good to know this part because is helping your logic.
I know it helps me a lot to see things as they are.

Now, back to your example, I believe, what you mean with your q12config.inc is
FINE EQU B'11010'   ;correct?
To only define this particular register bits, that is let's say [the most used] configuration in the large majority of my PICs.
I am right? I hope I am, because I learn something completly new with you today !
As always, thank you!
Title: Re: new member introduction and advice
Post by: mineiro on September 21, 2021, 09:32:19 PM
hello sir q12;
Yes, EQU is a constant.
When your source code grows sometimes will be hard understand if a number seen it's a reference to a memory address that can be a register or just a number. So, to a code be more easy to read we can create distinctions.
Imagine that you see number 6 in your source code. The only sure that you can have is: it's not GPIO register. If number 6 it's a symbol to be echoed in LCD or just part of some arithmetic that you're doing you need comment in your source code.

By q12config.inc I was refering that we can create our own config/equ file. Suppose that you have 2 LCDs, one have 2 pins, other have 3 pins. This means that both need different configurations. Now, suppose that the only difference from a pic point of view is that we need set pin 1,2 as output, while to use other LCD we need set pin 1,2,3 as output.
To make our life easy, we can create 2 config files, label that lcd2.inc and lcd3.inc. We can use same label equate in both. Like:
lcd2.inc
LCDON equ 00000011b
lcd3.inc
LCDON equ 00000111b

We don't need change our code anymore, only include files being used. Same name (LCDON) to different configurations.

Now think how you do this without EQU. Well, in our code I need set some pic register as output. But I have 2 lcd's with different configurations; so, I will create 2 source codes, one to each lcd. At some point you will ask: Is this 00000111b a configuration to set output bits, it's a symbol that will be echoed in lcd screen, or is just part of some arithmetic/logic that I'm doing?
Quote
So, in our code, and I know this part very well, if let's say for example we have:
                       __config _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC
then it means:__config          1                    1                   0                   10
and you can write it as: __config B'11010' and it means the same damn thing as  __config _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC
Fully agree. The only note is when you turn pic on/reset some pins can be high (1) by default instead of low (0).

Masm32 and mpasm are macro assemblers. They use similar facilities. You can create macros to repetitive codes, you can create bit fields with RECORD directive, ... .
Title: Re: new member introduction and advice
Post by: q12 on September 22, 2021, 06:27:56 PM
Can you think on a very short project that I can learn something new, here in masm32?
I have an inspiration blockage. I have no idea what to do next. Ideas come to me, but a bit too slow, especially when I'm not chasing anything specific.
Tell me for example, what projects did you build in your life, using assembler? The cool ones ! Heh.
Anybody is welcome to tell his stories, I will read them all. Promise.
Title: Re: new member introduction and advice
Post by: mineiro on September 22, 2021, 08:12:38 PM
No cool projects.

You don't need much to start.
You need know how to open/create/save files, allocate memory, show/receive data to/from user, and exit to O.S.
Title: Re: new member introduction and advice
Post by: daydreamer on September 22, 2021, 08:29:27 PM
I enjoy these strange attractors,great demo based on strange attractors :thumbsup:
http://masm32.com/board/index.php?topic=9402.0
cool 100% asm game :thumbsup:
http://masm32.com/board/index.php?topic=6200.0
I have mostly unfinished projects
Title: Re: new member introduction and advice
Post by: q12 on September 22, 2021, 09:20:10 PM
 Thank you mister daydreamer, those 2 examples are cool indeed. But a bit over my head at this point.
So, mister mineiro, I would like to learn how to manage data from memory. Im not sure how that works in PIC .... but I know I am working with something from it's memory, im not sure what exactly. I imagine, by setting a variable in code, that will store it in memory of the PIC? to be collected later by other part of the code and made some calculations with it? It's the only logic I got about managing memory.  I am kind of new to this 'memory' thing when comes to asm. The only thing I know for sure, is that both PC and PIC memory are volatile, when not powered, its entire stored information get lost, and they will reapear after the entire program restarts and re-initializes the same variables again. Is there anything else more obvious that i fail to remember about memory? Let's think on a simple lesson about this subject.

Title: Re: new member introduction and advice
Post by: daydreamer on September 23, 2021, 01:22:11 AM
Quote from: q12 on September 22, 2021, 09:20:10 PM
Thank you mister daydreamer, those 2 examples are cool indeed. But a bit over my head at this point.
typical asm goals,make asm game and asm demo
whats your short term and longterm goal with PIC?control things,some inventions,robot?
there are masm macros that will help you save/load variables to disk
dont know if crossdevelopment tools let you PIC save/load memory on PC disk

Title: Re: new member introduction and advice
Post by: q12 on September 23, 2021, 03:09:15 AM
to mister daydreamer
Quotewhats your short term and longterm goal with PIC?control things,some inventions,robot?
Wow, I didn't quantify at all what I will do and how much with PICs (although I have a pretty bunch of them). I am very upset (on myself) because I started learning PIC's some long time (~20years) ago , then very rarely throw a very fast look saying "aah, its hard" over the years, and Now... deciding to draw the line I suppose. It's a very long time personal ambition !!! I did catch the thing back then, I was speaking PIC language quite fluent for a very short period, but after that,  I just stop using it, dealing with 'shit' in my life. And now, when Im looking back, I say to myself, "I used to know this stuff Quite OK" and now I can not link A to B anymore. You loose it, if don't use it. Also, in this period I am putting together a very short and to the point tutorial for myself in the first place, but also made public, called "Easy PIC" using my artpages that I mentioned already in my other answers. The idea behind "Easy PIC" is that PIC's should be easy to learn ! If Proper Explained and Illustrated ! Here is recently made artpage2 : https://www.deviantart.com/q12a/art/q20210920-EasyPIC-2-Problems-892416332 (https://www.deviantart.com/q12a/art/q20210920-EasyPIC-2-Problems-892416332)  Im not sure how I will deal with this project, if I will even finish it, because I'm at 2 artpages down at this point and is very slow. I'll see. But like I said before, the PIC it's my drive to learn and experiment new stuff. Especially some assembler that I am quite alienated.
I am very open to everything at this point.
Your "crossdevelopment tools" is a very new concept for me ! It will be very cool if I can bypass pickit2 with simple serial port connection of some sort, although this days everything is USB... I remember back in the days, I was programming PICs using pascal language (and C, c++ for a bit) through a serial port RS232 I think it was, with 9 pins on it... hmmm or another port maybe? the port used for printer, which had like 50 pins on it? but I remember it was a serial port and not an USB. And I did used a "quick and dirty" breadboard circuit to program the PIC, long before I buy pickit2 programmer and it's demo/testing board. I loved programming through serial port directly from a high level language!!! I think it is VERY possible directly from asembly !!!  I know from experience it is possible to program the thing, without their "obligatory stuff". And I was programming like that a bigger and more complicated PIC , was a 16F84, that I still have it today.
Quotetypical asm goals,make asm game
Hmmm. So your point is to learn asm by trying to make a game, right? Like the one with the plane between the mountains, arcade style that you linked me. Actually I played those games on some hand held devices that I dont know their name anymore. Exactly like this model here: https://i.etsystatic.com/14707614/r/il/160fd1/1982339783/il_570xN.1982339783_789z.jpg (https://i.etsystatic.com/14707614/r/il/160fd1/1982339783/il_570xN.1982339783_789z.jpg)  I loved them at their time.
Yeah, it will be cool to shift in making a game, but I have some very limited experience in making games. I tried some stuff in my c# win app, but nothing worked. Also I tried in Unity, and I got in a point I didnt know how to do some stuff so I quit that too. I learned over the years what is hard and what is really hard. Haha.
I suppose, some very very very basic game just for learning asm, will definetly not hurt. I am thinking right now at bouncing ball game, that should be very basic to make, right? example here: https://www.101computing.net/wp/wp-content/uploads/break-out-game.png (https://www.101computing.net/wp/wp-content/uploads/break-out-game.png) Let's play !
Quote...control things,some inventions,robot?
I already have 100pcs DIP8 and another 100pcs SMD PIC12F508. They were VERY cheap that's why I took so many. First, I want to have no problems with programming them. Second, I will do a couple of automation projects. I have a very cool project built from 1 year ago still in tests and still as prototype, still with bugs that I learned to accept them, haha. It is working like 90% of the time. And I did included 1x12F508 PIC in the entire project, but it is mostly an analog project. I am very proud of it. Heh. So yes, other automation future projects to use the PICs. Also robots, I have some very cool robot plans, simple enough and very practical, but... ugh... I know I can make them but not with what I have. In time. Definitely, PIC asm programming will help speed up their birth into reality.
Title: Re: new member introduction and advice
Post by: mineiro on September 23, 2021, 06:33:05 AM
I read that you use Proteus. Do you have electronic knowledge? Both, analog and digital? Well, diodes, transistors, capacitors, inductors, impedance, signal gain, band pass filters, active/reactive potency, ... ?
Link some sensors in pic.
I have seen a book from 80 very cool, Digital Computer Electronics by Malvino. This book tells how to create a 8 bit processor. You can simulate/emulate that in Proteus.
Title: Re: new member introduction and advice
Post by: q12 on September 23, 2021, 03:12:23 PM
 To mister mineiro
  Hmmm, haha, it's a lot to discuss about this chapter, I will refrain as much as I can, haha. First of all, I am not an electronist or electrician. I don't have full knowledge in electronics. But I do have knowledge to some degree. I build this thing : https://www.deviantart.com/q12a/art/q20210621-Led-Wings-Circuit-SensitivityControl-883289626 (https://www.deviantart.com/q12a/art/q20210621-Led-Wings-Circuit-SensitivityControl-883289626) This is actually that cool electronic project prototype I mentioned about. If it seems complicated on the first look, it is really not , when you split it in modules, which I did pretty evidently. This circuit is still in use today. You can see I use 1 PIC in this project for the remote control, and I had some help only for this particular module with the IR remote, since it was over my ears. But the idea to have it remotely activated, was my desire from the start. And it come out exactly how I felt it should. That's another reason I am very proud of it. Heh, yes. All those wires to the leds are manually soldered, also all led positions, It is all build on cardboard and a metal shield behind the cardboard, the entire design is thought and planned carefully and with patience. After I build it, I had some very special problems, near the wall, the sensor was catching very strong interference, so I had help to resolve that part. And the help extended to the remote control as well. But dont confuse the help I got with the entire project. The guy who helped me, was following my direction and I managed to make it work directly on the wall. At some point I was desperate, thinking I will not be able to make it work on the wall. That was the biggest problem after finishing it on the working table. It took months of building it, and then other months of testing it and calibrating it. Because I took breaks, it's how I work best. Again, it is still a prototype and it still have some major issues that I did not resolve yet, but in general lines, hell yeah, it is working beautifully and most important thing, it is working as I felt and planned and wished and desired from the very start. It is like an arrow thought into the hearth of the future. It is how I see it. Haha. I love it, and the other guy (s) really love the initial project as well. Some crazy dude (which i respect) build a copy of this thing but only on breadboard, using only opamps, reproducing my LM3914 basically. It was a crazy project and still is. Please, don't start me on it, because I will never stop, haha. Here is how it looks in reality: https://www.deviantart.com/q12a/art/IR-REMOTE-CONTROL-for-my-LED-WINGS-PROJEKT-877191366 (https://www.deviantart.com/q12a/art/IR-REMOTE-CONTROL-for-my-LED-WINGS-PROJEKT-877191366)
The Proteus program... sincerely I am using it rarely and is the only good microcontroler simulator I know. For everyday electronic simulations, I am using circuitjs. It is fenomenal good electronic simulator, highly recommended !
I downloaded and took a quick look inside the 8bit processor book you mentioned. I find it very interesting book ! Thank you for it. Very cool.
Title: Re: new member introduction and advice
Post by: mineiro on September 23, 2021, 08:10:10 PM
Very nice project, congrats.
Title: Re: new member introduction and advice
Post by: q12 on September 23, 2021, 11:07:41 PM
Thank you.
Title: Re: new member introduction and advice
Post by: q12 on October 02, 2021, 10:43:08 AM
QuoteI have seen a book from 80 very cool, Digital Computer Electronics by Malvino. This book tells how to create a 8 bit processor. You can simulate/emulate that in Proteus.
So, pretty much to build an 8bit processor in Proteus simulator.
I read the book until SAP2 (p179).
The explanations in the book are Awesome, I really like them !!! but it get very complicated, very quickly. I have a partial knowledge of the things he is saying in the book, but not everything.
I learned Proteus (better), it's interface and it's tools with this occasion.
I managed to make SAP1 (Simple As Possible 1) Computer in Proteus; but I get 4 errors I can not find the problem and the computer does not compute anything.
I managed to successfully simulate a working [Memory basic ROM] and a [Memory Small TTL 74189] in Proteus. (No errors in these2)
I attached all the files here in this message attachment. Please check my saved files and also see if you can repair my 4 mistakes I made in [8bitCalculator] file. When you have time of course. Thanks.
This was way out of my comfort zone and I take my time with it, enjoying my breaks because I had some very tough days with this project. It was hard and intense for me. But I did something!  :toothy:
(Recomanded to download) Full package(book+pictures+save files): https://drive.google.com/file/d/1Is9rTb8Lzl0tTTU_9srhOD0vbfhBiXo8/view?usp=sharing
Title: Re: new member introduction and advice
Post by: q12 on October 07, 2021, 09:20:07 AM
I build the circuit of SAP1 as best as I could but it come out wrong for some reason. I tried to debug it, and I managed to clean the errors. What I did, I inserted on the red "error" wire for most susceptible IC's, 4 jumpers, for each "error" wire. And I did it for only 2 IC's that I suspected them the most. Now, with those jumpers activated, it's like it was before, teoretically, a simple wire, but now I dont get any errors of any kind. The circuit still behaves as before. 4 leds ON, 4 leds OFF in the 8 Wire/Word Bus.
When simulation is running, the 555 Clock circuit is doing it's thing, pulsating the Clock output. And every IC is receiving fine this signal on it's clock input. I put a couple of logic probes and they show me the activity of this Clock. So it was relatively easy to debug to this point. I believe it is more complicated than this. I believe my circuit is OK. Excepting those weird errors I got before which got solved by inserting jumpers on the wires (which should not solved the problem, but it did). Haha.  I believe it is a couple of Manual switching and a specific order of switching some elements there, also the ram programming as well. So its a bit more complicated problem.
---
The bottom line is: I push it as far as I could. I failed, but I learned some interesting stuff along the way, even if I failed the main goal.
- Now, what should I practice more to be better with assembler in both worlds (windows processors and PIC's) ?
Give me something good, another book perhaps or another tutorial from a website somewhere, as long as it is good.
Title: Re: new member introduction and advice
Post by: q12 on October 07, 2021, 11:08:14 PM
Update:
At 75% of the book(the last big chapter),  the autor is talking about a couple of processors. So my bright idea was to search for an emulator or simulator for an old processor like he described and listed. The most popular emulator I find and downloaded and installed already is this one: https://emu8086.en.lo4d.com/windows
But then, after researching some more, and also paying attention to the book, I find this one, unfortunatly online version and not stand alone : http://www.6502.org/tools/emu/  in which the very first link will send you to http://www.6502asm.com/
This is my first encounter with these emulators. I have no idea what I should do first. In a way, problem is solved with the SAP (SimpleAsPossible) circuit, because I completely switched towards a much better choice , these 2 functional emulators. You should have tell me about them/prepared me , but is good either way.
Being said that, I still look like an idiot to these emulators. Is good that I have the option of using them, and I SUPPOSE the perspective of learning the true basics of asm. Smaller number of instructions and the most basic ones compared with the new processors asm instructions, is my logic. Im not completely sure. What is your advice guys?
Also, I'm not so sure if I am doing the right choice of splinting between PIC asm and Windows asm, to be super sincere. I think I got in some more deep mud than staying only in PICs world. I really hope I didnt do a stupid choice here. I need your thoughts about this problem as well.
Please, and thank you.
P.S. Alone, I usually do shit, but with you guys, I have a better chance. I believe in you.
Title: Re: new member introduction and advice
Post by: daydreamer on October 08, 2021, 12:36:15 AM
about 8086 emulator:dosbox combined with masm commenting out ;.686p,restrain masm to only accept minimum=8086 instruction set,the instructions only using general purpose registers is good start,before fpu,MMX,SSE,AVX instructions
I seen projects many years ago,based on old PC,with printer port used for controlling lawnmower and other things,24 bits port using in and out instructions,but DOS-only,windows stops you from using hardware directly
Title: Re: new member introduction and advice
Post by: q12 on October 08, 2021, 01:52:47 AM
Update:
I managed to download the stand alone version of this exact javascript emulator for 6502 proccesor : http://www.6502asm.com/
I find it on github as a .js inside a .zip package and is working excelent as a simple win-web app. Haha.
I also find a very helpful tutorial page specific for this 6502 web emulator: https://skilldrick.github.io/easy6502/ and also from a link inside it, the NMOS 6502 Opcodes http://www.6502.org/tutorials/6502opcodes.html#BNE; although, he said about a second opcode page that today doesnt work anymore... 1 should be good enough i guess. I am using it as I am progressing through its very simple and to the point tutorial. Very easy and direct explanations. This is the type of tutorial I like !!!
Im at 50% of it at this point, and I started today. It looks simple and fast but I actually read everything in it and try it manually in a paralel web window with the emulator in it. Not fun to work like that at all but, is doing something. Haha.
This is what I wanted all along, this kind of wetting my delicate fingers into the real asm. Believe me, I reach my goal with this little tutorial. Well, its more like a step than a final goal. Its an important step.  I like that I can actually draw the squares on the black screen and represent the adresses and bytes. A very good introduction on how to use that asm Monitor with 16 x 00 hexadecimal per each line in it. Ive seen this monitors before, but never knew how to use one. Now I start to get it. It is exceptional specific. "Go exactly there and set that and you're done." But you must what "that" means.
So this is my progress so far... in progress with this tutorial.
Title: Re: new member introduction and advice
Post by: mineiro on October 09, 2021, 04:15:13 AM
So you ended SAP (simple as possible processor). Congrats.
I remember seeing inside proteus program a full 8086 processor done with virtual eletronic components. We can also use masm binaries files and check whats happening inside processor, or how processor is doing that. Proteus have some virtual devices to play, it's nice. Well, it's an industrial program, very strong.
Title: Re: new member introduction and advice
Post by: q12 on October 09, 2021, 09:51:16 AM
Quote from: mineiro on October 09, 2021, 04:15:13 AM
So you ended SAP (simple as possible processor). Congrats.
Yaaah... I finish the SAP but is still with errors in it. I managed to clean Proteus output errors, but internally is still bugged. SO, no it is not usable what  circuit I made there. I personally don't trust it. But I learned a lesson about logic gates and proteus interface itself. I will not be able to use that circuit.
But, I find an alternative to the problem and im walking on it right now. In the book last chapters, are mentioned a couple of processors and their respective directives. So... I concentrate on the most basic one, the 6502 and I find some VERY interesting stuff on internet in regard of it. I am now practicing the 6502 specific asm directives on an 6502 emulator. I was surprised to see the way this asm is written comparative with Intel asm. I also find some free tutorials about how to program this 6502 and also how to build a complete 8bit computer around this processor. Very interesting is that it is still in production ! with some new updates on it, but still the same thing as the original. I am fascinated. I am pushing as hard as I can on understanding it's asm language. It is a LOT to take in. And the most difficult part for me is to see the practicability in all what I am learning. After I will finish this 6502 'step', I will have some interesting questions for you.
Title: Re: new member introduction and advice
Post by: q12 on December 24, 2021, 01:42:53 AM
 Happy new year 2022 !
Hello again. It passed 1and half month from my last post. I sensibly thought to not bother you with my quest into PIC asm here. So I got into Microchip forums and things did not go Normal at all with them.  :thdn: :thdn: :thdn: :thdn:

I am back to you in the hope you can guide me into how to debug in asm for Intel chips. Or any simple instructions CPU (preferably old and simplistic) but I dont mind the CPU on my machine, which is very new and possibly with very complicated instruction set. My target still remains PIC asm but I will bent towards this way of doing and resolving things (because I have no alternative) and I believe very much, that it will apply to PICs in the end.
My greatest hole in knowledge is debugging CPU instructions (either is intel or PIC - I strongly believe its the same routine for ANY CPU). 
Please, correct me in my assumptions I made here. I am guessing about this stuff since ... you know, I dont really know the entire full mechanics. I am not a rookie though, I know some stuff, but very basic, barely applicable. What I know, I know from tutorials and I dont know that much. I have a bit of experience with asm debuggers in general, im not completely new to them, so im not at 0.

What types of debuggers and how many can you recommend ? What do you successfully and routinely use?
A good introduction tutorial into debuggers for asm will be a good idea as well. I respect and trust more what YOU will recommend than my instincts on google. It's too much garbage on google these days.
Thank you and I do understand this is a hard chapter to ask from you !
(if you are like me and get easily bored by the new year's eve...haha)