General Assembly Thread

General Assembly Thread: Ask your questions about assembler languages here.

I'm just getting into assembly, and I noticed that there's twelve general purpose registers (not counting the base pointer, instriction pointer, etc -- just those that can be used for storing program values) on x86-64, and thirty on ARMv8. Are they usually all being used, or are there usually some registers that aren't being used for something and are empty? So far I've only written simple programs and I haven't disassembled more complicated programs yet, so I don't know.

Also, is it possible to add a value to a subsection of a register (i.e. add a value to al after moving something into eax) without destroying whatever is in the other 24 bits of the eax register, or is the eax register cleared before adding the value to al?

For example, if I was to assemble:

mov eax, 3
mov al, 2

and then read the value stored in eax, would it show 2 because the 3 stored in eax was overwritten, or would it show a composite value? Would it be any different if I used the add instruction instead of mov to put 2 into al? What about if I used ah instead of al?

Other urls found in this thread:

friedspace.com/assembly/cpuregs1.php
farid.hajji.name/blog/2010/05/25/hello-world-on-the-bare-metal/
wiki.osdev.org/Main_Page
tptp.cc/mirrors/siyobik.info/instruction/BSWAP.html
jaist.ac.jp/iscenter-new/mpc/altix/altixdata/opt/intel/vtune/doc/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc251.htm
twitter.com/SFWRedditGifs

If you're into assembly, have you tried kolibriOS? it's not one for regular desktop use, but it's incredibly small and really shows the power of assembly.

you can use EBP/ESP if you want meight. most compiled x86 code uses EBP/ESP for the local variables/function arguments but it doesn't have to. some instructions such as PUSH,POP,RETURN, etc use ESP/EBP though so it makes more sense to use them for the stack

EAX is just one value which is 32 bits or 4 bytes. AL and AH are just names for parts of EAX. If you modify AL you're saying to modify the least significant byte of EAX. If you read AL you're saying to read the least significant byte of EAX.

mov eax, 3EAX=03000000mov al, 2EAX=02000000mov eax,FFFFFFFFEAX=FFFFFFFFmov al,10EAX=10FFFFFFmov ah,20EAX=1020FFFFmov eax,3add al,2EAX=05000000add ah,1EAX=05010000

your picture is off or I'm not understanding it. EAX is more like the picture here (tor users cant upload pics):
friedspace.com/assembly/cpuregs1.php

What is a good assembly language for a newbie like me to pickup after I learn C?

Yep.
Think of it this way, there's one 64 bit 'A' register (rax) and you can access subsets of it with eax,ah,al. They're like pointers into the register.

x86. It's designed to be written by humans and people actually write in it. Most other machines rarely have assembly sections outside of the OS.

Are there any good resources for x86 that use the AT&T syntax?

So what's the difference between x86 and ARM in terms of writing programs?

ARM is much more strict. As an example, unaligned access on x86 is a performance penalty but a fault on ARM. There's less syntactic sugar on ARM. But there's also less legacy cruft that a newbie doesn't know to ignore. Almost no one writes ARM assembly in the real world as ARM is usually used in low power applications, not high performance ones.

But wouldn't people be more inclined to use handwritten assembly in situations where performance is limited?

And does anyone but OS and BIOS manufacturers still write handwritten assembly on any platform? I'm learning it both because I'm interested in the internal workings of programs and because I'm interested in researching malware, but unless you're an autiste or are going into the security industry I don't see it being used at all. I'm transferring from a community college to a four-year institution, so maybe that's why, but at my old school I saw lots of "learn Python" classes, but nothing on learning assembly. And when I see those "which programming languages to learn for the best probability of employment" polls, assembly isn't even part of the poll.

Does anyone outside of niche fields even use assembly any more? And will I ever get a job outside of niche type jobs where knowledge in assembly is required or even recommended? Will knowing assembly and having a CS degree help prevent me from being stuck with code monkey Pajeet jobs for the rest of my life?

I'm still going to learn assembly anyways, since I'm genuinely interested in the subject regardless of how it affects my employability, but I'm curious.

Cool thread. I don't know any languages but just yesterday began learning this stuff. Trying to learn, I should say.

dump resources, plox

If they don't need more performance, why would they?
Yeah, I do occasionally in networking but I do everything I can to avoid it. Knowing assembly usually lets me restructure C code until I get the compiler producing what I want or cobble it together with builtins.
No.
No one asking about employment prospects of learning assembly will ever be good enough to compete for those jobs, so don't worry about it.

Those all get used. The rest of the world is much more sane (which isn't saying much), but cross-platform compilers and kernels have to carry around utterly retarded shit because x86 is so crippled in comparison.

I like the Z80 in Game Boy.

farid.hajji.name/blog/2010/05/25/hello-world-on-the-bare-metal/

I'm interested in trying this sort of thing out are there any decent references for the hardware though?

...

try wiki.osdev.org/Main_Page

You have to do some shift nonsense to be able to access the greatest 32/16 bits of the registers. :/

Or just use bswap
tptp.cc/mirrors/siyobik.info/instruction/BSWAP.html

Is this faster than shifting?

Shifting and masking is pretty normal when doing assembly anyway.

Yeah, I know. It's just another instruction you need, because Intel/AMD didn't add high order registers for 32 and 64 bit.

I can't think of a situation where I'd ever have needed one.

SSE thingy, PSHUFD--Packed Shuffle Doublewords

jaist.ac.jp/iscenter-new/mpc/altix/altixdata/opt/intel/vtune/doc/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc251.htm