Assembly language variable order
Jack Buffington
Posts: 115
I'm just a few days into working with the Propeller chip and so far everything is working out nicely for the most part but this one has me stumped. I have a program that I am working on in assembly language that is doing what I expect. Now I am trying to add some additional functionality to it now and am about to set up a bit of code that will let me do indirect addressing by modifying a register. I haven't added any self modifying code yet. I simply have a variable that will hold an address for another variable. Right now I have mention of it in two places in the code. The first is at the top of the code where I initialize it with
mov onTaddress,#0
The second is later in the code where I try add four to the variable.
add onTaddress,#4
Adding the second line causes my program to go haywire even though no other part of the code makes use of it. I have it declared as a long, as are all of the other variables in the program. If I try adding zero to it, everything works OK. Immediately before the add I have a rdlong statement. I tried sticking a nop between them in case there is some sort of timing issue because of the seven cycle thing for hub operations. That didn't work. I have found that changing the order that I declare my variables does make a difference. I have tried locating it differently in my variable list and in one location, the program will function almost normally. The difference is that it appears that sometimes onTaddress is being written to the next variable down in the list which I just happen to be copying to my outputs shortly after that in the code so I am seeing that on the attached LEDs.
Does anyone have any ideas on this one?
mov onTaddress,#0
The second is later in the code where I try add four to the variable.
add onTaddress,#4
Adding the second line causes my program to go haywire even though no other part of the code makes use of it. I have it declared as a long, as are all of the other variables in the program. If I try adding zero to it, everything works OK. Immediately before the add I have a rdlong statement. I tried sticking a nop between them in case there is some sort of timing issue because of the seven cycle thing for hub operations. That didn't work. I have found that changing the order that I declare my variables does make a difference. I have tried locating it differently in my variable list and in one location, the program will function almost normally. The difference is that it appears that sometimes onTaddress is being written to the next variable down in the list which I just happen to be copying to my outputs shortly after that in the code so I am seeing that on the attached LEDs.
Does anyone have any ideas on this one?
DAT PWM_Asm org mov memoryAddress,par ' memoryAddress now contains the memory location for LEDvalues[noparse][[/noparse]0] in main memory mov onTaddress,#0 ' because I am always going to use the same pins as PWM outputs, I am going to manually set that here mov dira, iodirs mov loadCycle,#0 PWM_Loop mov outPins,#0 ' clear the variable that will hold the pin states ch00 cmp onT+0,PWMcycle wz,wc if_z_or_c add outPins,mask + 0 ch01 cmp onT+1,PWMcycle wz,wc if_z_or_c add outPins,mask + 1 ch02 cmp onT+2,PWMcycle wz,wc if_z_or_c add outPins,mask + 2 '<snip> ' I have more of the PWM code here but since it is all the same, I have omitted it. '</snip> ' decrement the cycle. If it goes below zero, set it to 255 sub PWMcycle,#1 wc if_nc jmp #displayIt 'skip over this if it isn't rolling over ' if it makes it to here then it has just finished up a PWM cycle. ' Now it is time to load a PWM variable from system RAM. It only loads one ' byte at a time to reduce the pause before a new PWM cycle starts. mov PWMcycle,#254 'load a value from main memory. Because the destination is changing, I need to use 'some self modifying code to do that. {:selfMod01 rdlong onT+0,memoryAddress ' the destination of this address will be changed by other code mov tempLong,memoryAddress add tempLong,#4 rdLong onT+1,tempLong } ' move the address pointer add onTaddress,#12 '<--- Here is the problem line of code ##################################################### add loadCycle,#1 cmp loadCycle,#192 wz if_z mov loadCycle,#0 '' Update IO Pins displayIt mov outa,outPins jmp #PWM_Loop 'onTaddress long Mask long |<0,|<1,|<2,|<3,|<4,|<5,|<6,|<7 long |<8,|<9,|<10,|<11,|<12,|<13 long |<14,|<15,|<16,|<17,|<18,|<19 long |<20,|<21,|<22,|<23,|<24,|<25 long |<26,|<27,|<28,|<29,|<30,|<31 onTaddress long ' if I have it located here, it works but sometimes clobbers outPins outPins long 0 iodirs long $00FFFFFF memoryAddress long curAddress long 'onTaddress long ' if I have it located here it doesn't work PWMcycle long 0 tempLong long 0 onT long 255[noparse][[/noparse]192] ' on times for the PWMs loadCycle long 0
Comments
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Life may be "too short", but it's the longest thing we ever do.