I am totally lost when it comes to assembly language. My teacher just decided one day at the end of this semester to give us a programming assignment in assembly language and has barely taught us anything. I have to use five subroutines: main, add, subtract, multiply, divide and cannot use any global variables (no .BLOCK variables). main should read in the two values and pass them as parameters to the other 4 subroutines. My addition and subtraction work fine, but multiplication and division i have no idea on. I am still pretty confused on stacks and haven't been able to find much info on them in this format of assembly language. Any help would be appreciated.

BR main

param1: .EQUATE 6
param2: .EQUATE 4
sum1: .EQUATE 0
add: SUBSP 2,i
LDA param1,s
ADDA param2,s
STA sum1,s
DECO sum1,s
CHARO '\n',i

param3: .EQUATE 6 
param4: .EQUATE 4
sum2: .EQUATE 0 
subtract: SUBSP 2,i
LDA param3,s 
SUBA param4,s
STA sum2,s 
DECO sum2,s 
CHARO '\n',i

param5: .EQUATE 6 
param6: .EQUATE 4
sum3: .EQUATE 0
multiply: SUBSP 2,i
LDA param5,s
ASLA ;no idea if this is what is supposed to be used to multiply or not
STA sum3,s 
DECO sum3,s 
CHARO '\n',i

;DIVIDE METHOD ;need to find quotient AND remainder
param7: .EQUATE 6 
param8: .EQUATE 4

num1: .EQUATE 2
num2: .EQUATE 0
main:SUBSP 2,i
STRO msg1,d
DECI num1,s 
STRO msg2,d
DECI num2,s
DECO num1,s
CHARO ' ',i
CHARO '+',i 
CHARO ' ',i
DECO num2,s
CHARO ' ',i
CHARO '=',i 
CHARO ' ',i
CALL add
DECO num1,s
CHARO ' ',i
CHARO '-',i 
CHARO ' ',i
DECO num2,s
CHARO ' ',i
CHARO '=',i 
CHARO ' ',i
CALL subtract
DECO num1,s
CHARO ' ',i
CHARO '*',i 
CHARO ' ',i
DECO num2,s
CHARO ' ',i
CHARO '=',i 
CHARO ' ',i
CALL multiply

ADDSP 2,i  

msg1:.ASCII "Please enter the first positive value (0 to quit): \x00"
msg2:.ASCII "Please enter the second positive value (0 to quit): \x00"

Not sure how much this will help, but I had to do a factorial program using pep8 for one of my CS classes as well a while back. Looking back here is a multiplication function (i think) I defined and used. It uses parameters as well.

; Mult (num1_in, total, value)
a: .EQUATE 4 ;num1_in
b: .EQUATE 18 ;total
c: .EQUATE 2 ;num1_val
mult: LDA a,s ;while num1_inside >= 1 loop
SUBA 1,i
BRLE end_mult
LDA b,s ;total := total + num1_value;
ADDA c,s
STA b,s
LDA a,s ;num1_inside := num1_inside - 1;
SUBA 1,i
STA a,s
BR mult ;end loop;

It's been a long time since I've looked at this so I can't guarantee it does what I think it does, but I believe it does multiplication using parameters. What book are you using? I used a book called Computer systems by J. Stanley Warford. I'd look and see if you can find a copy of this book at a library or something. I thought it explained the language very well.

- John

This question has already been answered. Start a new discussion instead.