Shop OBEX P1 Docs P2 Docs Learn Events
A couple of future assembly addons to manual? — Parallax Forums

A couple of future assembly addons to manual?

Erik FriesenErik Friesen Posts: 1,071
edited 2008-08-14 15:38 in Propeller 1
I about fell off my chair today when (this will be a duh moment for veteran programmers?) I figured out that the : is special in that its use means a name can be repeated more than once as long as it is in a different sub.

Another nice addition would be a self modifying code demo.

Can someone give me a good explanation of how the movd and mov 0-0 self modifying code actually work?

Comments

  • hippyhippy Posts: 1,981
    edited 2008-08-12 23:04
    How good do you need ... ?

    here    mov  $100,#123
    
    
    


    That writes the value 123 into Cog memory location $100.

    This will move $1AB into the destination part of the instruction at 'here' creating a 'mov $1AB,#123'. When 'here' is jumped to, 123 will be written to Cog memory location $1AB.

            movd here,#$1AB
            jmp  #here
    
    
    


    Because the destination register used in the instruction at 'here' is modified it has become a de-facto practice to use 0-0 to show a field ( destination or source ) which will be modified ...

    here    mov  0-0,#123
    
    
    

    Post Edited (hippy) : 8/12/2008 11:09:54 PM GMT
  • TimmooreTimmoore Posts: 1,031
    edited 2008-08-12 23:22
    The rule for : is not once per sub but once per label without a :
  • Cluso99Cluso99 Posts: 18,069
    edited 2008-08-13 10:29
    I think there should be a statement to the effect "for conditional execution (all instructions) see IF_x page nnn" for the JMP instruction. This is where most programmers will look for conditional execution and the JMP does not mention this.
  • AleAle Posts: 2,363
    edited 2008-08-13 12:47
    Cluso99:

    On the manual, page 348 where the Assembly language elements are described... it says that one of the elements are conditions, and sends you to page 368, where the first statement is that all assembler instructions have the optional field condition and so on. Before anyone tries to learn assembler.. reading the manual is one of the priorities. After all my time with the prop, the simulator and the code written... I miss here and there a detail. The manual is not very clear sometime to show differences with other processors, but no one do that anyways. There is no substitute for a good, careful and complete read to the manual. Any shortcut (like the ones I do) lead to bugs, misunderstandings (like REV recently, read the "rev is driving me crazy" thread for an example, I read the manual but still I thought It worked some other way...), frustration and un-enjoyment. Books do not bite.. well I'm not sure of that, but they produce allergy, well history books anyways wink.gif
  • Cluso99Cluso99 Posts: 18,069
    edited 2008-08-14 00:00
    I am one of the 15% ?? (according to Apple's data in the 1980's) that read the manual. However, when I wanted to recheck the actual if codes I had to scan the whole manual to find it - I think there should be a mention and reference in the JMP section - that is where I first looked and the manual implies that a JMP is unconditional!!!.

    I know the IF_x reference is on the previous page of the manual, but I do believe a reference should be on the JMP page. After all, we are trying to get everyone on board the prop aren't we? If we don't make suggestions to improve the docs, no improvements will ever be done. (same goes for typo's but I can't remember where they were)

    That was merely my take on it - to simplify it for others, and an obvious pointer to it.
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-08-14 02:37
    On page 312 it says the # is for,

    "Assembly literal: used to indicate an expression or symbol is a literal value rather than a register address"

    I know I'm probably wrong but it seems to me it should say,

    Assembly literal: used to indicate an expression or symbol is a register address rather than a literal value"



    Probably just disgust over the nth time I have forgot the #.
  • Cluso99Cluso99 Posts: 18,069
    edited 2008-08-14 04:58
    It appears to be used differently for a JMP than a MOV

    e.g.

    JMP #HERE 'stores the address (register if you like) to jump to
    JMP HERE 'jumps to the address pointed to at HERE (commonly called an indirect jump)

    MOV SOMEWHERE,#HERE 'stores the address (register if you like) as an immediate value
    MOV SOMEWHERE,HERE 'stores the data located at the address HERE into a location at the address SOMEWHERE

    MOV SOMEWHERE,#0 'stores the immediate value into a location at the address SOMEWHERE
    MOV SOMEWHERE,0 'stores the data located at the address HERE into a location at the address SOMEWHERE

    Hope this helps.

    I would like to see an optional warning generated when the # is missing for a JMP/JMPRET and the CALL allowing to remove the # with an optional warning.
  • AleAle Posts: 2,363
    edited 2008-08-14 05:38
    call only allow arguments preceded for a #, it complains if it is not there, well my compiler does, but for jmp is completely optional, you may want it direct or memory indirect (without #). That most jumps are direct does not mean much, the compiler does not know. It may not be a bad idea to search for jmps without # when the program makes something funny. (Or may be a configurable switch....)
  • Cluso99Cluso99 Posts: 18,069
    edited 2008-08-14 13:10
    That was my point. You cannot use CALL without the #. I wanted to do an indirect call so had to do the JMPRET, but it is easier to read a call. I'd really rather see an indirect descriptor like JMP @here.
  • hippyhippy Posts: 1,981
    edited 2008-08-14 13:29
    I'd really rather see an indirect descriptor like JMP @here

    Agreed, though '@' is yet another additional ( and conflicting ) use for the token, so I'd settle for ' jmp *reg' or 'jmp [noparse][[/noparse]reg]'.

    It's all well and good saying take care in writing code but when one makes the mistake it's incredibly hard to see the mistake or debug. While 'jmp #reg' makes perfect sense with the Cog architecture, people from other microcontrollers are used to 'jmp label', 'jmp @reg'.
  • Cluso99Cluso99 Posts: 18,069
    edited 2008-08-14 15:38
    Agreed, and unfortunately I have made this mistake too many times :-( And I've been programming micros since the release of the 6800 in 1976, and computers longer.
Sign In or Register to comment.