Channels ▼

Al Williams

Dr. Dobb's Bloggers

Assembly Synonyms

January 12, 2010

If you read my recent article about my custom CPU with one instruction , you probably figured out that even though the processor only knows about a move instruction, the assembler provides more common op codes (like JMP or CALL) and translates them into the appropriate move. The Maxim MAXQ (another single instruction computer) does the same thing. But the practice isn't just limited to one instruction machines.

 

Think about the popular Atmel AVR chip. Suppose it didn't have a shift left or rotate left instruction (it does, but play along with me for a minute). What would you do? Shifting left is the same as multiplying by two, but it would be wasteful to multiply just to get a shift. But in 3rd grade you learned that 2x is the same as x+x, right? The AVR can do that. An ADD instruction is (in binary) 000011 RDDDDDRRRR (where R and D are bits showing which two registers to add together Rd=Rd+Rr).

Oh wait, the AVR does have a shift instruction called LSL. We'll just use that instead. Its opcode is: 000011 DDDDDDDDDD. Which is, of course, the same as an ADD where Rd==Rc! So the CPU apparently had 3rd grade math also.

A rotate left, by the way, is the same as ADC R,R. So you do a shift and you add the carry bit. There are many similar examples throughout the CPU world. The SPARC ret instruction is the same as a jmpl instruction, for example. The NOP on the ARM CPU is actually a useless move instruction.

Shakespeare wrote, “That which we call a rose. By any other name would smell as sweet.” Apparently CPU and assembler designers agree.

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video