# New to assembly language

1. Jan 20, 2014

### thankz

I need a good 64 bit assembly book for beginners, can you recommend one, i'm kinda short on cash so I can only afford one.

I have a few 32 bit books like -Linux assembly, high level assembly, and peter nortons assembly but I got to admit they aren't very good. I want to play around with turning my bios rom into a small operating system and messing with bootloaders and stuff. I only have a windows laptop so I guess i'll be using masm. question is their a 64 bit version? and where can I get it?

also I need to practice on an 8 bit assembler where can I find one that is like masm or runs in an emulator?

sorry to sound so needy lol, but I also am looking for the old intel cheat sheet, I think it was called the blue book or something(had it once) that list all the opcodes, operands and mnemonics
? the 8 bit and if it exists the 64 bit one.

I got the amd 64 bit programming manuals what else do I need, i'm just starting to get back into programming after years away from it.

2. Jan 20, 2014

### voko

Frankly, I am not even sure books on assembly are being written and published these days.

EDIT: I see that some books are "in store". The few that I checked out seem to be updates of books first published a decade or two ago. So I would guess Norton's book, which was first written in late 80's, should not be much worse.

If you have 32 bit books, stick with them even if they are not too good, make sure you can write a 32 bit program that actually works. The transition to 64 bits won't be too difficult after that.

The books you must have are Intel's/AMD's references/manuals on their CPUs. I have personally used mostly Intel's. They won't teach you how to write bootloaders and BIOSes, though. I do not think there is any book that will. In fact, writing those has very little to do with knowing how to write assembly code and much to do with how your chosen platform works from ground up. That is a lot of arcane knowledge and your best bet are open source implementations - study them and learn from them.

Masm is included with visual studio. I know that VS 2012 Express for Desktop (free version) had it, both 32 and 64 bit flavors. Not sure about later versions. GCC has an assembler as well.

Last edited: Jan 20, 2014
3. Jan 20, 2014

### thankz

I have visual studio 2005 so i'll poke (lol)around and see if I can find it. I don't want to use at&t syntax and i'm only using windows right now so gcc is out. I was surprised to see a bunch of 64 bit asm books on amazon I just need a recommendation on which one to get. I have two books on bios's from the days when I wanted to be a virus writer lol so i'm comfortable exploring my computers internals.

ps please don't tell me to use debug.com to write asm lol, I really would like an 8 bit assembler or emu to practice on, if anyone can find those cheat sheets I really would appreciate it.

4. Jan 20, 2014

### voko

What is an "8 bit assembler"? debug.com is a 16-bit assembler. I have not checked that in a while, but at least some time ago some 32-bit version of masm would produce 16 bit code, that was the question of using the SEGMENT directive correctly and then some linker options. The cheat sheets are the IA32 ref manuals I mentioned above.

5. Jan 20, 2014

### rcgldr

The bios runs in 16 bit real mode, using 32 bit prefixes if needed to access 32 bit operands / registers. You'd need to setup some tables and switch to protected mode in order to run in 32 bit or 64 bit mode.

You need to be running on a 64 bit version of windows. VS2005 includes ml64.exe which is the 64 bit assembler. Note the "removal of older features" in this wiki article section:

http://en.wikipedia.org/wiki/X86-64#Architectural_features

For VS2005 64 bit assembler projects, I use a custom build step (instead of letting VS2005 default a build step for .asm source files). Right click on the .asm source file(s) and create a custom build step:

command line - debug:

ml64 /c /Zi /Fo$(OutDir)\example.obj example.asm command line - release: ml64 /c /Fo$(OutDir)\example.obj example.asm

outputs:

\$(OutDir)\example.obj

To get C function names as used in assembly code, I write a dummy C program using /Fa option to produce assembly code to get the names.

example source for stand alone assembly code (using VS2005 / 64 bit windows):
Code (Text):

_DATA   SEGMENT
_DATA   ENDS

_BSS    SEGMENT
_BSS    ENDS

PUBLIC  wmain
EXTRN   __imp_malloc:PROC
EXTRN   __imp_free:PROC
EXTRN   __imp_clock:PROC
EXTRN   __imp_CreateFileW:PROC
EXTRN   __imp_WriteFile:PROC
EXTRN   __imp_CloseHandle:PROC

_TEXT   SEGMENT

wmain   PROC
sub     rsp,64                  ;allocate stack space
;       ...
xor     rax,rax
ret     0
wmain   ENDP
_TEXT   ENDS
END

Last edited: Jan 20, 2014
6. Jan 20, 2014

### thankz

thanks for the replys, I have some catching up to do, i'll have some more questions in the future.

7. Jan 20, 2014

### thankz

I guess they don't have a 8 bit assembler, I was looking for something like this:
http://nanochess.110mb.com/emulator.html [Broken]

Last edited by a moderator: May 6, 2017
8. Jan 20, 2014

### voko

Why do you need an 8080 assembler? It is very remotely related to IA32.

9. Jan 20, 2014

### thankz

I thought i'd start on something simple i'm just starting to remember things like little/big endian byte order you'll have to forgive me :)

10. Jan 20, 2014

### voko

Stick with IA32/x64, forget 8080. Or go with ARM. Do not waste your time on dead platforms. The only reason to study 8080 would be an interest in the history of computing, which I guess is not what you are after.

11. Jan 23, 2014

### SixNein

If you want to go that far into bare metal, I would recommend picking up a cheap raspberry pi B and learning arm assembly language. The raspberry pi will set you back like 30 or 40 bucks. And you can buy a cellphone charger to power it (Just make sure it's rated above 750 mil Amp). Oh and get a flash card reader/writer! With absolute barebones, you'll have to get a serial adapter for it: https://www.amazon.com/gp/product/B008AGDTA4/ref=oh_details_o02_s00_i04?ie=UTF8&psc=1

MASM64 or
http://www.japheth.de/JWasm.html

But I would recommend learning 32 bit first.

The 8 bit, 16 bit, 32 bit, 64 bit architectures just communicate how large the register sizes are going to be for that platform. So it defines the largest and smallest signed integer that can fit in a single addressable location. In addition, it also puts a limit on how much memory a computer can have because of the limit on the size of addressable locations. A 32 bit computer can have up to 2^32 = (2^2)(2^30) = 4 gigs of memory since we can only identify 2^32 locations.

On a 32 bit platform, the x86 architecture will have registers like eax, and it also provides smaller portions of eax:

eax - 32 bit register.
ax - The lower 16 bits of eax.
ah - the upper 8 bits of ax
al - the lower 8 bits of ax.

So if you wanted to play around with 8 bits, just limit yourself to stuff like al, bl, cl, dl, etc

But all of that being said, there should be a good reason for you to limit yourself. For example, suppose you want to write a platform that is going to operate on a battery powered cell phone that's using arm architecture. Even though you can use 32 bits, you might want to write the code in 16 bits and use thumb mode. Why? Under such a situation you're not trying to optimize for performance but power consumption.

Last edited: Jan 23, 2014
12. Jan 23, 2014

### rcgldr

Pentium processors have supported 36 bit addressing for quite a while. The server versions of Windows and some other operating systems support. Each process is limited to a 4gb virtual memory space, and part of that may be reserved for the operating system (I'm not sure how much if any is reserved).

http://en.wikipedia.org/wiki/PSE-36

ARM thumb mode is mostly used to reduce code size. Power consumption is about the same and the resgisters are still 32 bits.

13. Jan 23, 2014

### SixNein

Yes, the limitation can be partially overcome with virtual memory; however, a pointer is always going to be limited to the register size and thus provide a limitation on addressable locations. In virtual memory, pointers point to tables instead of physical memory addresses. So there is an extra layer added there to get around this issue. How much will the OS reserve? The OS shouldn't require anything since its virtual and not physical memory. The OS will just swap these tables in and out when it needs to do some things.

http://www.cs.uiuc.edu/class/fa05/cs433ug/PROCESSORS/Thumb2.pdf