Jump to content
Sign in to follow this  
Delphir

asm > pascal

Recommended Posts

Hello, people!

 

who can help me?

how can i realize this features in Pascal (for P2C compiler)

 

 

1. Check, if the Xth bit in Byte (B) is wether 0 or 1

2. how to use expressions declared in asm?

(e.g.       asm TRUE equ 1)

p2c compiler cannon find it if I use for example:

 

asm TRUE equ 1

 

var abc: boolean;

begin

abc := true; :P

Share this post


Link to post
Share on other sites
Guest Dave

Delphir,

 

Here is a little program that does the bit test you want.

It just uses "&" which performs a bitwise and.

 

#define true 1

#define false 0

 

program myprog;

var myvar: integer;

var mybool: boolean;

begin

 

myvar := 8;

 

if ( myvar & 8 ) then

mybool := true; { the bit is set }

else

mybool := false; { the bit is clear }

 

 

end;

 

I would say declaring constants is assembler is not recommend, the compiler pretty much ignores what appears in asm code, it just passed on to the assembler

Use #define instead.

 

I must admit I'm not a Pascal programmer, I've just done this for you. :cool:

 

Hope this helps  ::P:

Regards

Dave

Share this post


Link to post
Share on other sites

Thanks!

 

but will it work with such expressions as

PORTA or PORTB

to check the current status of the pins? there is no any procedure to _check_ it! only to set/cler: set_bit/clear_bit

 

how will looks a program, checkin the first bit in PORTA?

Share this post


Link to post
Share on other sites
Guest Dave

Delphir,

 

Here is some code, it does check a few bits of PORTA, but does nothing useful with them :P

 

#define true 1

#define false 0

 

program myprog;

var mybool: boolean;

begin

 

// check first bit

if ( PORTA & 1 ) then

mybool := true;

else

mybool := false;

 

// check second bit

if ( PORTA & 2 ) then

mybool := true;

else

mybool := false;

 

// check third bit

if ( PORTA & 4 ) then

mybool := true;

else

mybool := false;

 

// check fourth bit

if ( PORTA & 8 ) then

mybool := true;

else

mybool := false;

 

end;

 

Regards

Dave

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...