My very own twisted assembly and commands

Posted by Pirate-rob on Aug. 29, 2012, 2:04 p.m.

Now I've always wondered how the base of a pc works and what RAM and GHz and all that stuff mean. The only thing I really know is hard drive space. So I decided to make a program that simulates a PC the way I think it works.

Now to explain my way of understanding the inner works of PC:

I think that RAM is just a massive set of temporary variables that gets delete when the pc turns off.

I think that the hard drive is just a massive set of non temporary variables.

The GHz thing is how many assembly commands you run a second.

The screen is run by a massive array.

Now It has its own version of assembly and really bad syntax. I was wondering if anyone thinks there should be any other commands other then the ones listed below:

0001 - IF - The if statement

0002 - THEN - the then statement

0003 - END - the end to the if statement

0004 - SET VAR - sets a variable in the RAM to either a variable something returned or a number.

0005 - RANDOM - returns random value 0000-9999

0006 - Screen Red- sets a pixels red value on the screen

0007 - Screen Green - sets a pixels green value on the screen

0008 - Screen Blue - sets a pixels blue value on the screen

0009 - ADD VAR - Adds to a variable

0010 - ADD Multiply - Multiplies variable

0011 - KEY - key last pressed

0012 - GOTO - goto a line in the code

0013 - GETFILE - get a file/variable from the harddrive

0014 - SETFILE - set a file/variable to the harddrive

In case you want to try it for your self:

http://www.mediafire.com/?2v52c21q2ga2v1c

Syntax is a bit strange.

Comments

marbs 11 years, 8 months ago

You will be interested in this: 0x10c

It runs a version of assembly in your browser based upon the DCPU-16. It was made up by Notch.

You can find more information here.

While you have the general abstract overview correct - i.e. RAM is temporary, HDD is not - the rabbit hole actually goes much deeper than that:

http://en.wikipedia.org/wiki/CPU_cache

http://en.wikipedia.org/wiki/Paging

http://en.wikipedia.org/wiki/Virtual_memory

It is a lot to take in, but it is interesting to know your PC works. It is near impossible to truly understand exactly how all of your computer works, since each part is made up of many more interconnected parts; but you can attempt to understand how all the parts and systems work individually, and then appreciate how it can all come together as a whole.

ludamad 11 years, 8 months ago

IF, THEN, END are kinda out of place, as assembly instructions don't ever need any context. The rest, while unrealistic, obey this. IF by itself makes no sense without END. You have GOTO, which is a more assembly-friendly control structure, however to emulate IF's you'll need some kind of GOTO-IF-EQUAL or something similar.

ludamad 11 years, 8 months ago

Cryus: 'or something similar'

But yeah, as Stevenup hinted, this is far from a realistic assembly language anyway. The RANDOM opcode is kinda funny. I could see some assembly language created at some point thinking it was a good idea. But generally, RANDOM means RNG, RNG means state, which would make it very inflexible as a single opcode.

Pirate-rob 11 years, 8 months ago

The file system is a simple array which doesn't get dlete once the program is turned off unlike RAM

Mega 11 years, 8 months ago

This is an eery reminder of the way I used to think the internal system worked, until I got all those books about CPU design and computer architecture…

A lot of your 'opcodes' are actually higher-level constructs, which may or may not exist in HLA (High-level assembly), in some form or the other.

An interesting thing to remember is that the CPU is a very simple beast: It can only work with numbers, and not in very complex ways. Most of the constructs you present would take many real opcodes to implement on a real system, and the control structure opcodes are weird.

On that note, here's how something like if(a == 5) would be handled in x86

cmp [esp], $5
jne isFalse

isTrue:
  ; Do something
 jmp end
isFalse:
 ; Do something else
end:
 ; And so on

Pirate-rob 11 years, 8 months ago

Hm, well at least I learnt something, I thought assembly was written in numbers alone…

Here is sample code from it:

0004 00000001 0025

0004 = setvar

00000001 = 0000 0001 = variable 0,1

0025 = 25

So that code will set 0,1 to 25

I didn't realise assembly could use symbols, this will make it a lot easier now.

Mega 11 years, 8 months ago

Write and wrong, in some ways. Assembly is a mnemonic code that is translated into numbers via an assembler. Different instructions have different lengths, and for each possible addressing mode there is a different number (But one mnemonic label).

Before I ramble, I suggest taking a look at this:

http://www.plantation-productions.com/Webster/www.artofasm.com/DOS/index.html

Grab the PDF and start reading.

Pirate-rob 11 years, 8 months ago

I was randomly looking for 0x10c stuff (not sure why), when I came across this:

http://0x10cwiki.com/wiki/Assembly_beginner%27s_guide

Is this how assembly actually works?

Iasper 11 years, 8 months ago

I don't know that much about ASM but from my previous experiences I'm pretty sure how it works.

ludamad 11 years, 8 months ago

Its fairly realistic but:

Quote:

Sometimes you might want to only execute an instruction if a certain condition is true. This can be done by using the IFE, IFN, IFG instructions. They stand for "If Equal", "If Not Equal", and "If Greater" respectively. If the condition specified is not true, then the next instruction will be skipped.

Is typically not 'skip next instruction' but a conditional goto as was stated.