PDA

View Full Version : Machine Code --help please!


uniquity
10-11-2009, 07:13 PM
As an intro to one of my classes, we are required to write a small program in machine code (why? i wish i knew). the assignment is to count how many 1's are stored in a certain memory location using a loop. now, i get some of the basics, what i need help in is how to read and check each value in the memory location individually. any help would be greatly appreciated...i still don't completely understand the concept of machine code, so any type of breakdown will help A LOT. thanks in advance

Spookster
10-11-2009, 07:39 PM
What kind of sick demented professor would require an intro class to write in machine code? That went away in the 50's when assembly language was created. It is unlikely you would ever need to use that in modern times unless you had some obscure O/S that can't use any compilers in existence today.

Machine code is essentially binary instructions that the processor you are writing it for can understand. Assembly language for example allows you to use mnemonics in place of the binary instructions as they are easier to remember. So a command for subtraction would be written as SUB instead of it's machine code equivalent. The assembler/compiler then translates that into machine code for us.

Many modern day debuggers allow you to examine memory locations while you run the program in the debugger. But since you are writing this in machine code i'm not sure how easy this would be. You'd need a tool for examining memory and would need to know what memory address(es) to look at while your program runs.

uniquity
10-11-2009, 08:35 PM
i also failed to understand why i was learning machine code, but hey, gotta do what i gotta do right :o

but anyways, our professor has us using a simulator for the LC-3. It goes through the machine code source file line by line, and you can change the values within a memory register (he's using this to test our programs too).

cs_student
10-12-2009, 04:33 AM
I took a CS intro class at my high school during my junior year (last year). We were required to learn "machine code".

It was nothing like x86 assembly though. It only consisted of 9 commands and 8 registers.

I found it fairly simple. I think the purpose is to allow you to understand how instructions work, thus giving you a more profound understanding of what your compiler turns your code into.

Also assembly is used a lot in game development, OS development, and other programs which require utmost efficiency. Though, even in these fields, assembly is used rarely.

I think that every CS major should eventually learn machine language, but I think they shouldn't teach it in the intro classes.


cs_student

Spookster
10-12-2009, 11:50 AM
I took a CS intro class at my high school during my junior year (last year). We were required to learn "machine code".

It was nothing like x86 assembly though. It only consisted of 9 commands and 8 registers.

I found it fairly simple. I think the purpose is to allow you to understand how instructions work, thus giving you a more profound understanding of what your compiler turns your code into.

Also assembly is used a lot in game development, OS development, and other programs which require utmost efficiency. Though, even in these fields, assembly is used rarely.

I think that every CS major should eventually learn machine language, but I think they shouldn't teach it in the intro classes.


cs_student

Reading your post it seems like you are using the terms Assembly and Machine code interchangably. Just want to make sure you realize they are not the same thing. There's not really any point in learning machine code as it is processor dependent. Unless you plan on learning machine code for every type.