Assembly Language Example

bracketslash

Registered User
Joined
Feb 6, 2013
Messages
224
Wrote this up, figured that some of you might be interested in seeing it.

It searches memory locations E000 through E0FF and counts how many of these memory locations contains zeroes.

This is written for a 6502 (8-bit) microprocessor.

org 200h

ldx #0d ; clear the X register
ldy #0d ; clear the Y register



NextX *
lda 0e000h,x ; load E000+X into A register
cmp #0d ; compare the A register to 0
beq IncY ; if the A register == 0, IncY
inx ; increment the X register
cpx #0ffh ; compare the X register to 255
bne NextX ; if the X register != 255, NextX
sty 0275h ; store the Y register into memory location 0275
brk ; end the program

IncY *
iny ; increment the Y register
inx ; increment the X register
jmp NextX ; jump to NextX

end

Pretty basic ASM example.

Here's a quick sum-up of ASM for those who have no clue what it is: ASM is the most unambiguous, low-level (besides machine code) programming language there is. Every command has one and only one corresponding machine code instruction. Assembly language is processor-specific. Assembly language (aims to) use hexadecimal which has a one-to-one correlation to binary. All of this combined gives you utmost control over the processor and memory but a major downside is that it may take 100 lines to do something that may take 1 line in any higher-level programming language.

Hope you enjoyed it :-)
 
Or you can go even lower level and write with the opcodes in binary :-P ...

Took a class in uni that exposed me to asm, and the LC-1 (little computer 1 lulz)... Interesting stuff, but all I can say is praise Dionysus for people who write (or have written) compilers...
 
Or you can go even lower level and write with the opcodes in binary :-P ...

Took a class in uni that exposed me to asm, and the LC-1 (little computer 1 lulz)... Interesting stuff, but all I can say is praise Dionysus for people who write (or have written) compilers...

Indeed. My junior year assignment is to write a compiler and an operating system from the kernel up. :-) Should be fun.
 
Well, the basic stuff isn't too bad... but then you add more and more and more and more and now we have object-oriented stuff and... yeah, it's pretty insane how far things have come in the past 50 years...
 
Back
Top