Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

In what kind of situations, assembly language will be the only solution?

share|improve this question
add comment

5 Answers 5

up vote 9 down vote accepted

When you want to write low-level stuff like:

  • an Operating System
  • drivers and communication with custom hardware/electronics.
  • an Compiler (assembler can be the output)
  • optimizations
share|improve this answer
2  
It is often possible to use C for raw memory-mapped I/O, with volatile (and, if appropriate, const) pointers to specific locations. –  David Thornley Nov 1 '10 at 20:35
add comment

When you absolutely need to do the following (in Debug, that wonderful program):

-F 200 L1000 0
-A CS:100
xxxx:0100 MOV AX,301
xxxx:0103 MOV BX,200
xxxx:0106 MOV CX,1
xxxx:0109 MOV DX,80
xxxx:010C INT 13
xxxx:010E INT 20
xxxx:0110
-G
Program terminated normally

NOTE - Run at your own risk as this is non-recoverable.

See this page for more uses: Tools and References for the MBR and OS Boot Records (search for "Debug")

share|improve this answer
2  
For those of us not familiar with the interrupt table, what does this do? –  Mason Wheeler Nov 1 '10 at 2:52
1  
@Mason This will perform the most wonderful function of wiping your master boot record! You must do this to allow a low-level format when FDISK cannot remove partition(s) on your drive. See Wiping Clean the Master Boot Record or the search results here. –  Mark C Nov 1 '10 at 2:56
    
One note, but debug wasn't included with Windows 7. –  rjzii Nov 1 '10 at 2:56
    
@Rob And I think it was "neutered" to some degree on WinXP. (History in 2nd link, specifics here.) –  Mark C Nov 1 '10 at 2:57
add comment

Microcontrollers.

share|improve this answer
8  
Couldn't you just write a cross-compiler on some other platform instead? –  dsimcha Oct 31 '10 at 14:25
    
@dsimcha: True, I'm definitely wrong on that point. Updated. –  Scott Whitlock Oct 31 '10 at 18:59
add comment

When doing embedded programming for a small microcontroller, even if a C compiler is available for the CPU, you may need to resort to assembly language either to reduce the size of the code or to achieve maximum speed, or (usually) both. Some microcontrollers have have only a few KB of program memory, and less than 1 KB of RAM.

However compilers for microcontroller architectures are pretty good these days, and I seldom have to resort to assembler anymore.

share|improve this answer
add comment

I compile C code to assembler to study how the compiler works. Try to play around with the output. Understand what happens under the hood when we choose some construct. Like if-else-if, switch case and array lookup. How does the compiler treat them? Which will be faster? Assembler helps a lot in understanding how higher constructs work.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.