flat assembler
Message board for the users of flat assembler.
 flat assembler > High Level Languages > I am translating C to Pascal and need help.
Author
arcangel

Joined: 19 Aug 2009
Posts: 39

# I am translating C to Pascal and need help.

I am translating a C to Pascal and there are some instructions that are not as translation. Does anyone could help me?

Thank you very much in advance

The definition of variables is as follows:

 Quote: unsigned short pc; unsigned short opcode; unsigned short I; unsigned char V[16]; unsigned char memory[4096];

The instructions with which I have problems are:

 Quote: opcode = memory[pc] << 8 | memory[pc + 1]; switch(opcode & 0xF000) V[(opcode & 0x0F00) >> 8] = V[(opcode & 0x00F0) >> 4]; if(V[(opcode & 0x0F00) >> 8] > V[(opcode & 0x00F0) >> 4]) V[(opcode & 0x0F00) >> 8] = (rand() % 0xFF) & (opcode & 0x00FF); I += ((opcode & 0x0F00) >> + 1; memory[I + 2] = (V[(opcode & 0x0F00) >> 8] % 100) % 10;

Thank you very much in advance
24 Jul 2013, 12:58
dogman

Joined: 18 Jul 2013
Posts: 114
Join the free pascal mailing list. They have genius Pascal programmers!
24 Jul 2013, 13:11
arcangel

Joined: 19 Aug 2009
Posts: 39
24 Jul 2013, 16:17
rugxulo

Joined: 09 Aug 2005
Posts: 2177
Location: Usono (aka, USA)
Traditional (ISO standards: 7185 or 10206) Pascal doesn't have bitwise operations, at least not natively. So "<< 8" would just be "* 256". Later non-standard variants (Turbo, Delphi) and offshoots (Modula-2, Oberon) either had explicit bitwise operators or library functions or offloaded such things to equivalent of a BITSET type. (See here or here or here for more.)

P.S. If the calling convention and object format (etc.) are compatible, most compilers let you link in compiled code from other languages. FPC and GPC already support C-based functions, so you don't have to manually convert it to Pascal, just make sure everything is declared and externed properly and just link it. It's not quite as easy as it sounds, but it's far from impossible and by default officially supported. For FPC, see here; for GPC, see here.
24 Jul 2013, 20:35
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------Blog General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum