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.
|''||ASCII Character String|
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.
|file: /Techref/scenix/lit.htm, 2KB, , updated: 2007/2/23 13:42, local time: 2022/6/25 03:17,
|©2022 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?|
<A HREF="http://www.massmind.org/techref/scenix/lit.htm"> Parallax SX, Programming SX, Literal Values in Instructions</A>
|Did you find what you needed?|
Welcome to massmind.org!
Welcome to www.massmind.org!