I am having a hard time getting my program to execute correctly. it is supposed to take two numbers entered by the user store them in an array, and reverse the array so when added they display correctly. i am to get the numbers using a procedure two seperate times, and reverse the arrays three times (reverse each entered number, and the sum array). furthermore when the user has entered one more than the max number of keys a + or = sign is to be entered for them. eg. i have the computer program set to take 3 numbers for each array so when the user enters a fourth a + or = sign should automatically appear. I cannot get the program to do this, or go any farther. I was hoping someone could let me know where i am going wrong with my code.

here it is:

BOZOS_CODE SEGMENT    ;The "logical" segment is named BOZOS_CODE
             ASSUME CS:BOZOS_CODE   ;The "assume" statement tells the assembler
                                    ; that BOZOS_CODE is a code segment (CS)
             ORG 100h            ;In case we decide to convert the program
                                 ; to a COM file (makes 256 "empty" locations)

           START: jmp begin      ;Since this is a code segment the first non-
                                 ; directive item must be an instruction. We
                                 ; jump around our data area

	  
	  num_of_bytes EQU 3
	  first_num db num_of_bytes dup (0), '$'
	  second_num db num_of_bytes dup (0), '$'
	  the_sum db num_of_bytes + 1 dup (0), '$'
	  message_1 db 'Enter the first multi-digit number (up to 12 digits in length) followed by a'
		    db '"+" symbol then enter a second multi-digit number (up to 12 digits in '
		    db	'length) followed by a "=" symbol  $'
		  
                          

	  key_stroke db 'x$'
	  operand db 'x$'



GET_NUM:	 mov ah, 00h    ;Read keyboard function
                 int 16h        ;Call BIOS (return occurs when key is pressed)
                                 ;AL now contains the ASCII code of key pressed
		 
		 mov key_stroke, al

		 mov ah, 09h                ;Display string function
                 mov dx, offset key_stroke  ;Pass the starting address of string
                 int 21h                    ;Call DOS
		 
		 mov al, key_stroke

		 cmp al, cl   
		 jne continue
		 ret		;return

continue:  	 and al, 0fh

		 mov [BX], al
		 
		 inc BX
		
		 cmp [bx], ch

		 jbe get_num
		 
		 mov operand, cl
		
		 mov ah, 09h                  ;Display string function
                 mov dx, offset operand       ;Pass the starting address of string

                 int 21h          ;Call DOS
		 ret		  ;return

REV_NUM: 	 mov cl, [bx]

		 mov ch, [di]

		 mov [di], cl

		 mov [bx], ch

		 dec BX
		 inc di
		 
		 cmp di, bx
                                   
		 jae rev_num
		 ret
        
           
begin: 		  mov ax, cs     
                  mov ds, ax     

		  mov cl, 0      
		  
		  mov ah, 06h    ;Scroll-up window function
                  mov al, 0      ; Clear entire window
                  mov bh, 1ch    ; Display "attribute byte" for cleared area
                                 ;  Blue background/Red characters
                                 ;  Bit definitions: Blink|Background R,G,B|
                                 ;                   Intensity|Character R,G,B
                  mov ch, 0      ; Y = 0     (Corner coordinates of window
                  mov cl, 0      ; X = 0      to clear)
                  mov dh, 24     ; Y = 24        
                  mov dl, 85     ; X = 79        
                  int 10h        ;Call BIOS

		                                   
                 mov ah, 02h    ;Set cursor position function
                 mov bh, 0      ; Display page 0
                 mov dh, 0      ; Y position  25 rows    (Y: 0 -> 24)
                 mov dl, 0      ; X position  80 columns (X: 0 -> 79)
                 int 10h        ;Call BIOS

		  
		 mov ah, 09h              ;Display string function
                 mov dx, offset message_1 ;Pass the starting offset of the
                                           ; string to be displayed
                                           ; (the string to be displayed starts 
                                           ;  at the label message (in the data
                                           ;  area) and ends with a '$')
                                           ;Note: DS must point to the beginning
                                           ;      of the segment containing the
                                           ;      string to be displayed, e.g.,
                                           ;      mov ax, cs  (usually done at
                                           ;      mov ds, ax   the beginning of
                                           ;                   the program)
                                           ;Note: This display procedure updates
                                           ;      the cursor position as each
                                           ;      character is displayed
                 int 21h                  ;Call DOS
                 
		 mov bx, offset first_num
		 mov cl, '+'
		 mov ch, num_of_bytes
		 
		 call get_num
		
		 mov bx, offset second_num
		 mov cl, '='
		 mov ch, num_of_bytes       ;do i need to do this again?
		
		 call get_num
		
		 mov di, offset first_num
		 
		 call rev_num
		
		 mov di, offset second_num
		 
		 call rev_num

		 mov BX, 0   ;Index set to zero now
		 mov ah, 0   ;ah now used for carry, and is set to zero

adder:           mov al, first_num[BX]
		 add al, second_num[BX]
		 add al, ah
		 
		 cmp al, 9
		 jbe no_carry
		 mov ah, 1 
		 sub al, 10
		 jmp make_ascii

no_carry: 	 mov ah, 0
		

make_ascii:	 or al, 30h
		   
		 mov the_sum[BX], al
		 inc BX

		 cmp BX, num_of_bytes 
		 je fix_carry		; if array is full jump to fix carry character
	   	 jmp adder
		 
fix_carry:	 or ah, 30h
		
		 mov the_sum[BX], ah
                           
		 mov bx, num_of_bytes - 1
		 mov di, offset the_sum
		 
		 call rev_num 
		
		;to display sum
	 	 
display: 	 mov ah, 09h                ;Display string function
                 mov dx, offset the_sum     ;Pass the starting address of string
                 int 21h                    ;Call DOS

		 ;To exit to DOS

exit:             mov ah, 4ch    ;Exit to DOS function
                  mov al, 0      ;ERRORLEVEL = 0
                  int 21h        ;Call DOS



	   BOZOS_CODE ENDS
           END START           ;You MUST have a carriage return after START

thank you

I wrote up an NASM source with similar functions to your
own code. A function for reversing the array, for
adding the two arrays as unpacked BCS, and for entering
values are here. Call to array reversal is commented out.
After three characters have been read in either a + or =
sign is displayed, numbers are added, result is printed.

bits 16
org 100h

jmp Ldead_stag
glass  times 0x3 db 0x0
neck   times 0x3 db 0x0
withme times 0x4 db 0x0
Ldead_stag:
mov bx, glass ; our first sequence of
              ; arbitrary digits from user
mov dl, '+'   ; a maltese cross character, plus
call stolen_dec
mov bx, neck  ; our second array
mov dl, '='   ; equality symbol
call stolen_dec
;mov bx, glass
;call permutate
call sum_dumb
call flashed_sum
ret

stolen_dec: ; DL-A + or = with 
                    ; permission BX-points to array
push dx
mov cx, 3
stolen_dec_talks:
mov ah, 0x1
int 0x21
and al, 0xf
mov [bx], al
inc bx
dec cx
jnz stolen_dec_talks
pop dx
mov ah, 0x2
int 0x21
ret

sum_dumb:
mov bx, glass+2
mov si, neck+2
mov di, withme+3
xor ah, ah
mov cx, 3
sum_dumb_l:
mov al, [bx]
add al, [si]
aaa
cmp ah, 0
jnz sum_dumb_addend
sum_dumb_imback:
add al, [di]
mov [di], al
dec bx
dec si
dec di
dec cx
jnz sum_dumb_l
ret

sum_dumb_addend:
mov [di-1], ah
xor ah, ah
jmp sum_dumb_imback

flashed_sum:
mov bx, withme
mov cx, 4
flashed_sum_again:
mov dl, [bx]
add dl, 0x30
mov ah, 2
int 0x21
inc bx
dec cx
jnz flashed_sum_again
ret

permutate: ; a array reversal BX=array 
                   ; assumes 3 byte array
mov di, bx
add bx, 2
mov cx, 2
permutate_again:
mov al, [di]
mov dl, [bx]
mov [bx], al
mov [di], dl
inc di
dec bx
dec cx
jnz permutate_again
ret

thanks it helps to see how you did it, im still having a hard time getting it to let me enter the 4th character and then forcing a + or =. My instructor wants us to have it do this:

"After the user has entered the maximum number of digits, the procedure should force the display of the termination character (a passed parameter) whether the user enters it or not as the next keypress.

In other words, the user might expect to enter the maximum number of digits allowed and then enter the termination character. To accommodate this, the procedure should wait for another keypress after the maximum number of digits has been entered (and stored in the array). After the user enters the next keypress the procedure should display the termination character and exit (i.e., return)."

I have tried several different ways, but i am just stumped...

I'm sorry I didn't know that you were required to let the
user enter a fourth character.
So they can enter a variable number of chars up to the
maximum amount,
and always use a termination character to indicate end
of input.
Also my code always expects three characters to be read
So thats why you had the reversal procedure,
cuz the number of characters read is not always three.
so
12
123
21
321
Thats neat.

ya its pretty cool, the arrays are then reversed and added into a sum array. then the sum array is reversed and the correct answer comes out. the original program without procedures works perfect but to break it down into using procedures gets tricky.

That's actually kind of funny, I usually have a hard time
not breaking my programs down into procedures.
I think it is essential to know what pieces of code
to encapsulate into procedures and how certain
levels of procedural abstraction should be performed.
Breaking some of your program's source code down into
procedures is only good practice, exercise,
wouldn't you say?

I don't know how different mine is from yours
now, I tried to translate your code to my assembler
and just said @^ck it.
But it will wait for an extra key press when max
chars are read, and will now read a variable number
of characters instead of three like the last I showed
you.
Termination character is 0xd Carriage Return.

bits 16
org 100h

jmp Ldead_stag
glass  times 0x3 db 0x0
neck   times 0x3 db 0x0
withme times 0x4 db 0x0
tmp    times 0x3 db 0x0
Ldead_stag:
mov bx, glass ; our first sequence of
              ; arbitrary digits from user
mov dl, '+'   ; a maltese cross character, plus
call stolen_dec
mov bx, neck  ; our second array
mov dl, '='   ; equality symbol
call stolen_dec
mov bx, glass
call permutate
mov bx, neck
call permutate
call sum_dumb
mov bx, withme
call permutate_b
call flashed_sum
ret

stolen_dec: ; DL-A + or = with permission BX-points to array
push dx
push bx
mov cx, 3
xor dx, dx
stolen_dec_talks:
;mov ah, 0x1
;int 0x21
;cmp al, 0x1b
call getkey
jc stolen_dec_helps
and al, 0xf
mov [bx], al
inc dx
inc bx
dec cx
jnz stolen_dec_talks
push dx
stolen_dec_walks:
mov ah, 6
mov dl, 0xff
int 0x21
jz stolen_dec_walks
pop dx
stolen_dec_helps:
mov bp, sp
call fixup
pop bx
pop dx
mov ah, 0x2
int 0x21
ret

fixup:
cmp dx, 0
jz fixup_e
cmp dx, 3
jz fixup_e
mov si, [bp]
mov di, tmp
mov cx, dx
cld
rep movsb
mov di, [bp]
mov si, tmp
mov cx, 3
sub cx, dx
add di, cx
mov cx, dx
rep movsb
cmp dx, 2
jz fixup_1
cmp dx, 1
jz fixup_2
fixup_e:
ret
fixup_2:
mov bx, [bp]
mov word [bx], 0
ret
fixup_1:
mov bx, [bp]
mov byte [bx], 0
ret

sum_dumb:
mov bx, glass
mov si, neck
mov di, withme
xor ah, ah
mov cx, 3
sum_dumb_l:
mov al, [bx]
add al, [si]
aaa
cmp ah, 0
jnz sum_dumb_addend
sum_dumb_imback:
add al, [di]
mov [di], al
inc bx
inc si
inc di
dec cx
jnz sum_dumb_l
ret

sum_dumb_addend:
mov [di+1], ah
xor ah, ah
jmp sum_dumb_imback

flashed_sum:
mov bx, withme
mov cx, 4
flashed_sum_again:
mov dl, [bx]
add dl, 0x30
mov ah, 2
int 0x21
inc bx
dec cx
jnz flashed_sum_again
ret

permutate: ; a array reversal BX=array assumes 3 byte array
mov di, bx
add bx, 2
mov cx, 2
permutate_again:
mov al, [di]
mov dl, [bx]
mov [bx], al
mov [di], dl
inc di
dec bx
dec cx
jnz permutate_again
ret

permutate_b: ; a array reversal BX=array assumes 3 byte array
mov di, bx
add bx, 3
mov cx, 2
permutate_b_again:
mov al, [di] ; begin  
mov dl, [bx] ; end
mov [bx], al
mov [di], dl
inc di
dec bx
dec cx
jnz permutate_b_again
ret

getkey:
push dx
getkey_l:
mov ah, 6
mov dl, 0xff
int 0x21
jz getkey_l
cmp al, 0xd
jz getkey_ignore
mov dl, al
mov ah, 2
int 0x21
pop dx
ret
getkey_ignore:
stc
pop dx
ret
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.