If I execute an instruction: MOV PSW, #07DH what is the active register bank? I believe its bank 2.
07DH = 01111101B Bank 3
In assembler, you can write constants in binary. You'd have saved yourself the problem if you'd written it in Binary! Always consider which is the most appropriate notation to use - and use it! (Aside: for this very reason, it's a real pain that 'C' doesn't provide a binary notation for constants!)
This should be reasonably portable:
#ifndef BINCONST_H #define BINCONST_H /* Binary constant generator macros evaluating to compile-time constants * * Based on work by Tom Torfs donated to the public domain * * Sample usage: * * B8(01010101) = 85 * B16(10101010,01010101) = 43605 * B32(10000000,11111111,10101010,01010101) = 2164238933 */ /* For up to 8-bit binary constants */ #define B8(b) ((unsigned char)B8__(HEX__(b))) /* For up to 16-bit binary constants, MSB first */ #define B16(b1,b0) (((unsigned short)B8(b1)<<8) | B8(b0)) /* For up to 32-bit binary constants, MSB first */ #define B32(b3,b2,b1,b0) (((unsigned long)B8(b3)<<24) | ((unsigned long)B8(b2)<<16) | ((unsigned long)B8(b1)<< 8) | B8(b0)) /* Helper macros not to be used directly */ #define HEX__(n) 0x##n##UL #define B8__(x) (((x&0x0000000FUL)?0x01:0) | ((x&0x000000F0UL)?0x02:0) | ((x&0x00000F00UL)?0x04:0) | ((x&0x0000F000UL)?0x08:0) | ((x&0x000F0000UL)?0x10:0) | ((x&0x00F00000UL)?0x20:0) | ((x&0x0F000000UL)?0x40:0) | ((x&0xF0000000UL)?0x80:0)) #endif
Well, that didn't work out too good. I'll post a link to binconst.h after a little while.
http://www.8052.com/users/dhenry/binconst.h
For your amusement this was a solution for 8 bit values I came up with a while ago: #define BIN(x) ((unsigned char)(((1##x##UL%2UL) | (((1##x##UL/10UL)%2UL)<<1) | (((1##x##UL/100UL)%2UL)<<2) | (((1##x##UL/1000UL)%2UL)<<3) | (((1##x##UL/10000UL)%2UL)<<4) | (((1##x##UL/100000UL)%2UL)<<5) | (((1##x##UL/1000000UL)%2UL)<<6) | (((1##x##UL/10000000UL)%2UL)<<7)))) Which allows things like: unsigned char x=BIN(01010101);
"For your amusement this was a solution for 8 bit values I came up with a while ago: #define BIN(x) ..." Which could also be at the core of 16-bit and 32-bit macros.
View all questions in Keil forum