Home > dotnetjunkies > A Microprocessor Story…..

A Microprocessor Story…..

Programming in 8086 can be a bit strange, you had to study the program, in a way memorize it and then you had to write it down on a sheet of paper, then you demanded an “OP Code” sheet and you would convert the program into hexadecimal code and then start up the emulator that looked like a mother board with a hex. keyboard  and a red LCD display on it, you had to set a start block for your program instructions by pressing some special keys then allocate the memory and then start entering the hexadecimal program instructions in the offset of memory and then you hit a key and then the program executes or did it ?.And if you made a mistake somewhere you had to reenter the instuctions.Well that depended on the kind of program you wanted to do, well if you wanted to add two numbers you had to feed in the values at some other place and do something I can’t recall  …or am I trying to forget?. It can be a bad experience if you have not much idea about what the “architecture” was.

You wake up in the morning after a night of trying to mug up more than “20” of these bizarre programs and in the morning you find that you can only recall the first two.Thats bad. And what’s worse is that you got a lab test and the professor insists that you learn two different kinds of these programs or else. You usher yourself into the lab with a couple of friend who can remember 10 of them, those luck bastards.You pick up the lottery ticket and you read.You are silent,enlightened.You read the question again and again.You wish you could return the lottery and get an other one,but then you look at the professor and you dread.Damn now, you can only remember the first two or three programs and the one you got doesn’t even belong to the first ten , and those guys next to you are putting there pencils to the test, soon they will demand “OP Codes” and punching in instructions, you stare at that 8086 emulator ( the thing that looked like a mother board with a number pad and a red LCD display) you start fiddling with the number pad maybe you could add two numbers, Na, may be write that conversion program, those were easy but … but how are you supposed to rotate that ! ? that Stepper-Motor (you got the program where you needed to write instructions to rotate a Stepper-Motor that was connected to the emulator clock-wise and counter clockwise ), you take it in your hand and try to recall if you ever did this before you wish you had. You ponder the meaning of life and what instruction sets had to play in it, the mystery of the universe could have been unlocked for you right there if you just remembered those magical instruction you needed to feed into that magical machine that would turn the Stepper-Motor clock-wise and counter-clock-wise and unleash the secrets of the universe. Finally you start rotating the motor with your hand, no, you can’t do that. You need to do it with the machine. You finally decide not to unlock the mysteries of the universe and catch some tea.Damn that Stepper-Motor. Well that was a long time ago. Looking back and doing some goggling you find that this may have been the key…
Now that looks simple doesn’t it?

; bin data for clock-wise
; half-step rotation:
datcw    db 0000_0110b
db 0000_0100b
db 0000_0011b
db 0000_0010b

; bin data for counter-clock-wise
; half-step rotation:
datccw   db 0000_0011b
db 0000_0001b
db 0000_0110b
db 0000_0010b

; bin data for clock-wise
; full-step rotation:
datcw_fs db 0000_0001b
db 0000_0011b
db 0000_0110b
db 0000_0000b

; bin data for counter-clock-wise
; full-step rotation:
datccw_fs db 0000_0100b
db 0000_0110b
db 0000_0011b
db 0000_0000b

start:
mov bx, offset datcw ; start from clock-wise half-step.
mov si, 0
mov cx, 0 ; step counter

next_step:
; motor sets top bit when it’s ready to accept new command
wait:   in al, 7
test al, 10000000b
jz wait

mov al, [bx][si]
out 7, al

inc si

cmp si, 4
jb next_step
mov si, 0

inc cx
cmp cx, steps_before_direction_change
jb  next_step

mov cx, 0
add bx, 4 ; next bin data

cmp bx, offset datccw_fs
jbe next_step

mov bx, offset datcw ; return to clock-wise half-step.

jmp next_step

The tea did taste good

Around the web:
* Hello World! in different programming languages including 8086

* 8086 microprocessor emulator with integrated 8086 assembler

Advertisements
Categories: dotnetjunkies
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: