Re: Assemble language discussion thread
First understand how division is preformed in computers... To us all computer is a wonderful machine which does all sorts of work.. But actually, this machine knows nothing more than addition!. Subtraction is addition of negative numbers, multiplication is repeated addition, division is repeated addition of complementary dividend.
now, for example, what is 12/4?
answer is 3. we get it by a long hand division(remember grade 2 math)
but the computer does it some what like this:
takes 12 and calculates how many times 4 can be subtracted from it! its just simple as it is. 12-4=8(1 time) 8-4=4(2 times) 4-4=0(3 times). It can no longer subtract 4 from 0 with out carry. so it assumes the quotient to be 3.!
So, let me explain it line by line...
mvi a,23h - loads the a register with 23h
mvi c,05h - loads the c register with 05h
sub c - subtracts 05h from 23h and places the answer in a register
inr b - increments b register for each subtraction count of 05h from 23h
jnc 0004h - if the carry flag is not set, then it jumps to 4th memory location.
dcr b - this is for adjusting the calculation
mov a,b - This is needed just to move the answer to a register.
hlt - stops the program.