flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > I am translating C to Pascal and need help.

Author
Thread Post new topic Reply to topic
arcangel



Joined: 19 Aug 2009
Posts: 39
arcangel 24 Jul 2013, 12:58
I am translating a C to Pascal and there are some instructions that are not as translation. Does anyone could help me? Embarassed

Thank you very much in advance Very Happy

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) >> Cool + 1;

memory[I + 2] = (V[(opcode & 0x0F00) >> 8] % 100) % 10;



Thank you very much in advance Very Happy
Post 24 Jul 2013, 12:58
View user's profile Send private message Reply with quote
dogman



Joined: 18 Jul 2013
Posts: 114
dogman 24 Jul 2013, 13:11
Join the free pascal mailing list. They have genius Pascal programmers!
Post 24 Jul 2013, 13:11
View user's profile Send private message Reply with quote
arcangel



Joined: 19 Aug 2009
Posts: 39
arcangel 24 Jul 2013, 16:17
Post 24 Jul 2013, 16:17
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 24 Jul 2013, 20:35
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.
Post 24 Jul 2013, 20:35
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.