please dont rip this site

Parallax SX Embedded Controller

Literal Values in Instructions

The source data for an operation can be provided by the instruction opcode itself rather than a register. An operand provided this way is called an “immediate” operand. In the syntax of the assembly language, the “number” or “pound” character (#) indicates an immediate value. Here is one example:

	mov W,#1 ;move immediate value 1 into W

The immediate value 1 is loaded into the W register. The 8-bit immediate value occupies an eight-bit field in the instruction opcode. Immediate or constant values can be represented in decimal, hexadecimal, or binary formats by useing a prefix.

Prefix

Radix

% binary
<none> decimal
$ hexadecimal
'' ASCII Character String

Examples:

	mov W,#142 ;move immediate value 142 into W
	mov W,#%10001110 ;move immediate value 142 into W
	mov W,#$8E ;move immediate value 142 into W
	mov W,#'A' ;move immediate value 65 into W

Constants should be replaced with equates when ever they are used more than once in a program or where they might be difficult to find in the future.

Often, constant values are calculated from other values to automate possible future changes in thier base values or to improve readability of the code. For example: If we wish to set two bit values currently at the 4th, 5th and 6th places with in a register using only one operation, we might construct an or fr, #%00111000. But what if the positions of the bit values change in the future to the 1st, 3rd and 8th bit? it would be better to define an equate for the bit positions and then calculate a mask to use in the or operation. In fact, if we realize that the fr.bit notation results in a value that is comprized of the bit number times 256 plus the register number, we can do the following:

myreg	ds 1
;ds assigns the value of the next unused register number to the label myreg
bitA	=	myreg.1
bitB	=	myreg.3
bitC	=	myreg.8

	setb	bitA
	;etc... easy to use bitA, B, C in bit operations.

	or myreg, #(1<<(bitA/256) | 1<<(bitB/256) | 1<<(bitC/256))
;shift a one into the bitA place and 
; combine it with a one shifted into the bit B place
; combine it with a one shifted into the bit C place
; to make the literal value.

Now we can make anychanges we like to the positions of bitsA thru C without needing to recode our application.

See:


file: /Techref/scenix/lit.htm, 2KB, , updated: 2007/2/23 12:42, local time: 2024/11/23 19:05,
TOP NEW HELP FIND: 
3.135.206.212:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://techref.massmind.org/Techref/scenix/lit.htm"> Parallax SX, Programming SX, Literal Values in Instructions</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to techref.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .