From: kalevi@kolttonen.fi   
      
   Rosario19 wrote:   
   > 8 bit cpu for access memory other than 0..255 location has need at   
   > last one 16 bit register and 16 bits operations, so i think that even   
   > a 8 bit cpu has to have int in C language as 16 bits   
      
   I do not know whether C standards permit 8-bit ints, but   
   cc65 is a real-world 6502 C cross-compiler available straight   
   from the standard repositories on Fedora Linux 43 and FreeBSD 15.   
      
   We can install cc65 and VICE emulator to do a simple test:   
      
   $ cat foo.c   
   #include    
      
   int main(void)   
   {   
    printf("%d\n", sizeof(int));   
    printf("%d\n", sizeof(void *));   
      
    return 0;   
   }   
      
   $ cl65 -o test.prg -t c64 foo.c   
      
   $ c1541 -format mydisk,01 d64 mydisk.d64   
      
   $ c1541 mydisk.d64   
   OPENCBM: opening dynamic library libopencbm.so failed!   
   D64 disk image recognised: mydisk.d64, 35 tracks.   
   Unit 8 drive 0: D64 disk image attached: mydisk.d64.   
   c1541 (VICE 3.9)   
   Copyright 1995-2024 The VICE Development Team.   
   C1541 is free software, covered by the GNU General Public License, and you are   
   welcome to change it and/or distribute copies of it under certain conditions.   
      
   c1541 #8> write test.prg test   
   writing file `TEST.PRG' as `TEST' to unit 8   
      
   c1541 #8> exit   
   Unit 8 drive 0: D64 disk image detached: mydisk.d64.   
      
   $ x64 mydisk.d64 &   
      
   VICE will load and run test.prg automatically on booting Commodore 64   
   emulation. We can observe the following:   
      
   --------------------------------   
   load"*",8,1   
      
   searching for *   
   loading   
   ready   
   run   
   2   
   2   
      
   ready   
   --------------------------------   
      
   6502, or rather 6510 on C64, hardware can do only 8-bit   
   machine language operations on math-capable registers, but   
   cc65 compiler indeed makes C language 'int' to be 16 bits just   
   like the pointers for memory addressing are 16 bits.   
      
   Z80, another 8-bit CPU, has machine language instructions   
   for doing 16-bit arithmetic by concatenating two 8-bit registers.   
      
   I do not think 6502 has such a feature in its instruction   
   set architecture.   
      
   br,   
   KK   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|