On Thu, 23 Jun 2005, Mario Mendes Jr. wrote: > OK, maybe not necessarily limited to pics, but.... > > So, I remember when I started reading about cpus/mcus a long time agon > about why banking and paging came about. > > Being a beginer, I do find banking and paging to be a nusiance, > nevermind making code a little more complex to deal with. > > But rather than trash the idea, what I wanted to know from the more > experienced guys in the list is: are there any actual benefits to > banking and paging? Is there ever a situation where banking and paging > actuall makes things easier/better? In theory banked and paged address spaces make for more compact program code since the addresses used for any indirect access will be shorter. But that is history (once upon a time code storage was extremely expensive and nobody had optimising compilers). On most 8 bit micros there were addressing modes for 'short' and 'long' distance of indirect objects. The 8080, Z80, MCS51 and most Motorola 8 bit CPUs all have this feature. When storage became cheap the banking (and shadowing which is a form of banking) became obsolete and they are still used only for acceleration (f.ex. the BIOS in a pc is copied to RAM and then mapped out during boot - code runs up to 100 times faster from ram than from flash BIOS), and in 'legacy' architectures (like mask programmed 4 bit cpus). I do not know why Microchip chose to go with banking and paging instead of making wider instruction words (to make room for the extra address bits). It may have saved some silicon real estate (in the form of less code storage bits required for the same task). Others went with wide words all the way. The ARM is a good example, its words encode a lot of information: example (from 'Introduction to the LPC2000'): if(Z==1) R1 = R2+(R3*4) encodes as: EQADDS R1,R2,R3,LSL #2 which is a single word on 32 bits. On a pic one would do: btfss STATUS,Z goto noz rlf R3,w ; w = r3 * 2 movwf R1 ; r1 = r3 * 2 addwf R2,w ; w = r3 * 2 + r2 addwf R1,f ; r1 = 2 * r3 + 2 * r2 + r2 = r2 + r3 * 4 noz: which takes 6 x 12 or 6 x 14 bits and only operates on 8 bit numbers in a 32-register file. So the pic consumes at least 72 bits of code to do 1/4 (8 bit registers instead of 32) of the equivalent single 32 bit ARM instruction word, and runs in 6 T cycles (the ARM takes 1 T cycle to do the job). On the other hand, a simple bit banging code can consume less space on a pic than on an ARM. E.g. toggling an output can be done as: movlw 0xFF,w mofvwf RB again: xorwf RB,f goto again the loop uses 2 x 12 bit words and runs in 3T per loop. An equivalent ARM loop will use 2 x 32 bit words and run in 2 or 3T (depending on MAM settings). so the PIC saves 60% code space because it uses narrower code words (which is possible due to banking). Peter -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist