Home

Bio
My Articles
Blog
Photo albums
Contact me

IT news
Articles


How multiplication is realized in a simple computer processor?

24 Apr 2007, 534 read(s)
Tags:


The assembly language can explain us how a computer actually works and thinks. As there is no multiplication function in a computer processor (I'm not sure if there is any in the newer ones, but I speak mainly for 8086 and the x86 family), I decided to find out how multiplication is realized through addition....

Sounds quite simple. Can you do it? Do you know how the computer calculates the simple x*y you write in Pascal or any other high-level language?

Calculating x*y...
  1. get
  2. mov bx, ax
  3. get
  4. mov cx, 0
  5. a: add cx, bx
  6. sub ax, 1
  7. cmp ax, 0
  8. ja a
  9. halt

What does this do and how?

First of all, this code gets two variables (X and Y) and stores them in two different registers on the processor. We are using the registers and not the memory here, because the registers work faster. Then, the code uses a third register to calculate the sum. This is done via a simple loop: the value of X is added Y times to this third register. Differently from high-level languages, we cannot create a for loop here. Instead, each time we add X to the third register, we decrease the value of Y with 1. Then, we check if Y is above zero. If it is, we continue to add. If not, we have the awaited result in the third register.


Comments

Martin Tsarev: Actually, this is my first assembly program
Dimitar Tabakoff: Tsarev OS is coming soon...... with the TFF (TabakoFF PC) architecture
Martin Tsarev: T&T (Tsarev & Tabakoff) computer system will soon be available...
Dimitar Tabakoff: I agree with that
Anonymous: Мечти мечти ....
Мартин Царев: Ще видим дали са мечти след някой и друг месец...
dk: Искам лицензирано копие на Tsarev OS и една T&T системка !!!!!
Мартин Царев: Аз гарантирам само за операционната система. Архитектурата не знам дали ще се прави или не. Ама Tsarev OS ще върви на x86 като за начало.
Dimitar Tabakoff: Архитектурата ще се направи но засега.....я има само на чертеж. Трябва някой да ме спонсорира или да участвам в състезание с проекта си. Но нищо не ми пречи да взема шлайфа, ножиците за ламарина и една стара кутия и да направя другия си нов проект - новата ти tabakoff компютърна кутия. В ния ще има място за водно охлаждане, частите ще са разположени така, че да се охлаждат максимално лесно, а махането и добавянето на хардуер ще става все едно махате или слагате CD в CD-ROM-a си. И всечко това ще е с прекрасен цвят, ефектни рисунки (които ще са като шаблони и ще се махат и слагат отделно), осветление и никакви болтове!
Martin Tsarev: Така постепенно ще променим тотално днешните представи за компютър, а?
Peter Slavchev: Ако първото копие не е з амен много ще се сърдя
Anonymous:

Add comment...