Questions About Storing Opcodes With Operands

Started by
14 comments, last by zozzaloka 7 years, 9 months ago

there is anywhere a general call stack in memory

thanks now I get that call stack memory is in some cpu and cpu must have a counter for stack algorithm. :)

Euhm, the stack itself is in memory, the cpu only has a pointer to it, which is unsurprisingly named "stack pointer" or SP.

Advertisement

which is unsurprisingly named "stack pointer" or SP.

oh I got it. I might see SP register and an opcode in Assembly.

In x86 the registers are

general purpose registers:

EAX - free to use, holds function return values

EBX - free to use

ECX - free to use

EDX - free to use

these are 32 bit registers, but can be referred to as 16 bits AX,BX,CX,DX or 8 bits AH/AL/BH/BL/CH/CL/DH/DL

pointer registers:

ESI - source index, which is paired with...

EDI - destination index - these two are used for rapidly advancing pointer values when performing work that reads from one buffer and writes to another

EBP - the base pointer - points to the base of the stack frame, convenient for referring to function arguments or local variables, but not really required since the compiler can work out the math from...

ESP - the stack pointer - points to the top of the stack

EIP - index pointer - holds the address of the next instruction to be executed (after the currently executing one), can't be mov'd to but jmp or call can set its value

segment registers (used by virtual memory model):

CS - code segment - pointer to page that holds the unpacked exe file (or whatever. the bytecode is in this page)

DS - data segment - pointer to page that holds the heap

SS - stack segment - pointer to page that holds the stack

ES - for an extra page

FS - for an extra page

GS - for an extra page

flags register:

EFLAGS - a register used to store binary flags set by various common operations - allows for basic branching logic by remembering the results of comparisons, etc. For example, when you use greater than/less than in C you're setting the SIGN flag, and a conditional jump statement like JLE (jump if less than or equal to) will read the sign flag when deciding whether to jump, so the statement:

if(x < 2) {

A

}

B

could theoretically be compiled as:

CMP 2,x //compare 2 to x - this performs an "implicit subtraction", that is it executes "2 - x" but does not store the result in a register, though it does set the sign bit and zero bit in EFLAGS according to the result of the subtraction.

JLE B //if 2 was less than or equal to x then jump ahead to B, otherwise just keep going

A //compiled code of A

B //compiled code of B

There are also usually sets of special registers depending on the feature set of the architecture. (usually things like SSE or MMX)

Old instruction set reference and general system explanation: http://css.csail.mit.edu/6.858/2015/readings/i386.pdf

Very old discussion of exe format: https://msdn.microsoft.com/en-us/library/ms809762.aspx

Modern resource (64 bit architecture): http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

Back in the early 1970s I stumbled on the little gem of a CARDIAC computer, which turned me on to programming and then I learned to dig computer science in general. If you want to learn how computers work at the opcode and register level there is nothing better, and you can join the maker set and build one yourself (complete with manual). I still have mine.

Stephen M. Webb
Professional Free Software Developer

Take a look at the documents on this page... it should have most of the answers to most of your questions.

http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html

-potential energy is easily made kinetic-

In x86 the registers are

wow I saw that all in assembly.

build one yourself (complete with manual).

interesting!:) I dreamed computer makers when I was reading "Computer Architectures and How To Build".

Take a look at the documents on this page

thanks:)

This topic is closed to new replies.

Advertisement