mc6603
03-26-06, 05:17 PM
Hello,
I'm taking this assembly programming class in college.. I have to write this simple program that will act as a cash register... Let me explain this better, for all you programmers, try to remember the first program you wrote in your first programming class. You prompt user for qty of several products.. compute total, sales tax and grand total... I have my entire program working... The only issue is with aligning my output. I know I have the correct logic, but for some reason it will only line-up sometimes.. I'm going to show you an example and maybe someone can help.. :confused:
Ok, here is my code to output the number....
OUTPUT_T:
mov dx, 0 ;initialize register dx
mov ax, Sales_Tax ;move the value of
div multiplier ;divide by 10
add dx, 30h ;add 30 hex to register
push dx ;save dx
inc counter2
mov Sales_Tax, ax ;move value of ax into
cmp ax, 0 ;compare 0 to ax
jne OUTPUT_T ;loop until ax == 0
call PRINTSPACE_T
PRINT_DEC_T:
cmp counter2, 2
jne TOCHAR_T
call DECIMAL
TOCHAR_T:
pop dx ;restore dx
mov ax, dx ;move the value of dx mov ah, 2 ;cout>> char...
int 21h
dec counter2 ;decrement counter
CONT_T:
cmp counter2, 0 ;compare 0 to counter
jne PRINT_DEC_T ;loop until counter == 0
mov counter1, 0
ret
Here is my code that lines up the numbers...
NOTE: call space just prints a space...
PRINTSPACE:
cmp counter1, 5
jne ONE
ONE:
cmp counter1, 4
jne TWO
call SPACE
call SPaCE
TWO:
cmp counter1, 3
jne THREE
call SPACE
THREE:
cmp counter1, 2
jne FOUR
call SPACE
call SPACE
FOUR:
cmp counter1, 1
jne EXIT
call SPACE
call SPACE
call SPACE
call SPACE
EXIT:
ret
I repeat these functions for sub_Total and Grand_total..
my first trial lines up fine.
xx.xx
__.xx
xx.xx
my second trial gets messed up. Its one space to far to the right.
xx.xx
__ x.xx
xx.xx
Now, before you think and say you just have to remove a space, let me explain.. I already tried that and it will move two spaces.. So it will look like this:
xx.xx
x.xx
xx.xx
This is making me very mad.. I know its probably something stupid, but I've been thinking about it for sooo long I need someone else to look at it to help..
Thanks in advance
I'm taking this assembly programming class in college.. I have to write this simple program that will act as a cash register... Let me explain this better, for all you programmers, try to remember the first program you wrote in your first programming class. You prompt user for qty of several products.. compute total, sales tax and grand total... I have my entire program working... The only issue is with aligning my output. I know I have the correct logic, but for some reason it will only line-up sometimes.. I'm going to show you an example and maybe someone can help.. :confused:
Ok, here is my code to output the number....
OUTPUT_T:
mov dx, 0 ;initialize register dx
mov ax, Sales_Tax ;move the value of
div multiplier ;divide by 10
add dx, 30h ;add 30 hex to register
push dx ;save dx
inc counter2
mov Sales_Tax, ax ;move value of ax into
cmp ax, 0 ;compare 0 to ax
jne OUTPUT_T ;loop until ax == 0
call PRINTSPACE_T
PRINT_DEC_T:
cmp counter2, 2
jne TOCHAR_T
call DECIMAL
TOCHAR_T:
pop dx ;restore dx
mov ax, dx ;move the value of dx mov ah, 2 ;cout>> char...
int 21h
dec counter2 ;decrement counter
CONT_T:
cmp counter2, 0 ;compare 0 to counter
jne PRINT_DEC_T ;loop until counter == 0
mov counter1, 0
ret
Here is my code that lines up the numbers...
NOTE: call space just prints a space...
PRINTSPACE:
cmp counter1, 5
jne ONE
ONE:
cmp counter1, 4
jne TWO
call SPACE
call SPaCE
TWO:
cmp counter1, 3
jne THREE
call SPACE
THREE:
cmp counter1, 2
jne FOUR
call SPACE
call SPACE
FOUR:
cmp counter1, 1
jne EXIT
call SPACE
call SPACE
call SPACE
call SPACE
EXIT:
ret
I repeat these functions for sub_Total and Grand_total..
my first trial lines up fine.
xx.xx
__.xx
xx.xx
my second trial gets messed up. Its one space to far to the right.
xx.xx
__ x.xx
xx.xx
Now, before you think and say you just have to remove a space, let me explain.. I already tried that and it will move two spaces.. So it will look like this:
xx.xx
x.xx
xx.xx
This is making me very mad.. I know its probably something stupid, but I've been thinking about it for sooo long I need someone else to look at it to help..
Thanks in advance