This article has been dead for over three months
You
Hi guys I need help debugging My program I'm not sure why it doesn't work I'm not THAT good at assembly so it might be a small bug. I wanted to post the code, But its a lot of code. Everything works fine until I need to input numbers I enter
mov ah,0ah but for some reason it skips that part.
Ill post the code anyways for anyone that wants to take a look.
I highlighted the part thats giving me problems but you guys can take a look at the last part of the assignment, that would also be great.
Thanx in Advance.
Problems start from line 336. (if you copy the code)
<pre><code>INCLUDE MACROS.ASM
data segment
sentence db 30h dup(?)
temp2 db 11h dup(?)
numbers db 100h dup(?)
crlf db 10,13,'$'
Sone db 'Enter First Sentance(Press Enter When Finished):',10,13,'$'
Stwo db 'The Number Of Words Is: ',10,13,'$'
Sthree db 'You Can Only Enter Small Letters!!!',10,13,'$'
Sfour db 'Please Enter 6 numbers',10,13,'$'
Sfive db 'Press Enter For Next Number',10,13,'$'
Letters db '00000000000000000000000000',10,13,'$'
num db 5,?,5 dup(0)
ct db '1',10,13,'$'
temp dw 31
data ends
sseg segment stack 'stack'
db 100 dup ()
sseg ends
code segment
assume cs:code, ds:data
input db 32,?,32 dup(?) ;get user input
num2 db 5,?,5 dup(0) ;number input
number db ? ;the converted number
base db ? ;base of number
digits db ? ;number of digits in entered number
multiply db ? ;increasing multiply constant - use to assembel number
Tab db 6 dup(0) ;array of the six numbers entered
TabSigned dw 6 dup(0) ;entered 'Tab' array as signed numbers
sum_signed dw 0
sum_unsigned dw 0
sign db ?
hex db '0h$'
;output display messages
msg1 db 'Sum of ''Tab'' numbers (unsigned - decimal): $'
msg2 db 'Sum of ''Tab'' numbers (unsigned - hexadecimal): $'
msg3 db 'Sum of ''Tab'' numbers (signed - decimal): $'
msg4 db 'Sum of ''Tab'' numbers (signed - hexadecimal): $'
msg5 db 'PSP address (hex): $'
msg6 db 'Data segment address (hex): $'
msg7 db 'Stack segment address (hex): $'
msg8 db 'Code segment address (hex): $'
msg9 db 'Sorted array ''tab'' (unsigned) :$'
msg10 db 'Sorted array ''tab'' (signed) :$'
;******** MACROS ************
PHex macro
mov ah,9
mov dx,offset hex
int 21h
endm
;*******************************************************************************************
Print1 macro number,base,sign ;sign=0 -> unsigned number, sign=1 -> signed number
local @Pos,@NumLoop,@Display,@Above9,@Next
cmp sign,1
jne @Pos
add number,0
jns @Pos
push ax
mov ah,2
mov dl,'-'
int 21h
pop ax
neg number
@Pos:
mov cx,0
mov ax,number
@NumLoop:
mov dx,0
mov bl,base
mov bh,0
div bx
push dx
inc cx
cmp ax,0
jne @NumLoop
mov ah,2
@Display:
pop dx
cmp dx,9
jg @Above9
add dl,'0'
jmp @next
@Above9:
sub dx,10
add dx,'A'
@Next:
int 21h
loop @Display
endm
;*******************************************************************************************
BubbleSort: ;sorting array function
push cx
sub dx,dx ;flag (if flag=0 -> end of sorting)
mov di,0
cmp sign,1
je @LoopSigned
@LoopUnsigned:
mov al,[bx+di]
cmp al,[bx+di+1]
jbe @ContinueUnsigned
@SwapUnsigned:
xchg al,[bx+di+1]
xchg [bx+di],al
inc dx
@ContinueUnsigned:
inc di
loop @LoopUnsigned
pop cx
cmp dx,0
loopne BubbleSort
ret
@LoopSigned:
mov ax,[bx+di]
cmp ax,[bx+di+2]
jle @ContinueSigned
@SwapSigned:
xchg ax,[bx+di+2]
xchg [bx+di],ax
inc dx
@ContinueSigned:
add di,2
loop @LoopSigned
pop cx
cmp dx,0
loopne BubbleSort
ret
;****************************************************************
Convert macro ;converts the entered number in base number.
;base can be modified.
push cx
mov multiply,1
mov ch,0
mov cl,digits
mov number,0 ;reset 'number' before start converting
mov di,cx
@MakeNum:
dec di
cmp di,0
jl @return
cmp num[di+2],'-'
je @IsNegative
mov al,num[di+2]
sub al,'0'
mul multiply
add number,al
mov al,base
mul multiply
mov multiply,al
loop @MakeNum
jmp @return
@IsNegative:
mov al,number
neg al
mov number,al
@return:
mov al,number
pop cx
endm
;******************** START *****************
start:mov ax,data
mov ds,ax
;************** * *******************
mov ah,9
mov dx, offset Sone
int 21h
mov cx,30
Again:
mov ah,9
mov dx, offset Sthree
int 21h
mov cx,31
input1:
mov ah,1
int 21h
cmp al,13
je Inputend
cmp al,20h
je add_space
cmp al,61h
jl start_again
cmp al,7ah
jg start_again
space:
mov dx,temp
sub dx,cx
mov bx,dx
mov sentence[bx],al
cmp al,20h
jne lt_count
loop input1
Inputend:
inc bx
mov sentence[bx],'$'
mov temp,bx
mov ah,09
mov dx, offset crlf
int 21h
mov dx, offset sentence
int 21h
jmp Stage2
start_again:
mov ah,09
mov dx, offset crlf
int 21h
mov ah,2
mov dl,7
int 21h
mov cx,26
mov bx,0
clear:mov dl,'0'
mov letters[bx],dl
inc bx
loop clear
mov ct,'1'
loop Again
add_space:
inc ct
loop input1
lt_count:
sub al,61h
mov ah,00h
mov si,ax
add ds:[Letters+si],1
loop input1
;*************** * ******************
Stage2:
mov ah,09
mov dx, offset crlf
int 21h
mov ah,09
mov dx, offset Stwo
int 21h
mov ah,09
mov dx,offset [ct]
int 21h
;************** * *********************
mov cx,26
mov dl,61h
mov bx,0
PrintLetters:
mov ah,2
int 21h
inc dl
push dx
mov dl,':'
int 21h
mov dl,Letters[bx]
int 21h
mov dl,' '
int 21h
pop dx
inc bx
loop PrintLetters
mov ah,09
mov dx, offset crlf
int 21h
;**************** * *****************
mov cx,temp
mov bx,0
mov si,0
mov ct,'0'
words:mov al,sentence[si]
mov temp2[bx],al
cmp al,00h
je Print_word
inc ct
inc si
inc bx
loop words
Print_word:
mov temp2[bx],'$'
mov ah,9
mov dx,offset temp2
int 21h
mov ah,2
mov dl,'('
int 21h
mov dl,[ct]
int 21h
mov dl,')'
int 21h
mov dl,' '
int 21h
mov bx,0
mov ct,'0'
inc si
cmp cx,0h
je stage5
loop words
<pre><code>;**************** 5 ******************
;Question #4:
stage5:
new_line
putstr Sfour
putstr Sfive
mov cx,6
mov si,0 ;number position at 'Tab'
@GetNum:
mov ah,0Ah
mov dx,offset num2
int 21h
mov al,num2+1
mov digits,al
mov base,10
Convert
mov Tab[si],al
inc si
new_line
loop @GetNum</code></pre>
lea bx,Tab
mov cx,6
mov dx,0
@DoSumUnsigned:
;sum of UNSIGNED numbers
mov ax,word ptr sum_unsigned
mov dl,[bx]
add ax,dx
mov sum_unsigned,ax
inc bx
loop @DoSumUnsigned
lea bx,Tab
mov cx,6
mov ax,0
@DoSumSigned:
;sum of SIGNED number
mov al,byte ptr sum_signed
add al,[bx]
jo @Correct
mov byte ptr sum_signed,al
inc bx
loop @DoSumSigned
jmp @DoneSumSigned
@Correct:
mov al,byte ptr sum_signed
cbw
mov sum_signed,ax
@again:
mov al,[bx]
cbw
add sum_signed,ax
inc bx
loop @again
@DoneSumSigned:
;print numbers : signed/unsigned & decimal/hexadecimal
putstr msg1
mov base,10
mov sign,0
Print1 sum_unsigned,base,sign
new_line
putstr msg2
mov base,16
mov sign,0
Print1 sum_unsigned,base,sign
mov ah,2
mov dx,'h'
int 21h
new_line
putstr msg3
mov base,10
mov sign,1
Print1 sum_signed,base,sign
new_line
putstr msg4
mov base,16
mov sign,1
Print1 sum_signed,base,sign
mov ah,2
mov dx,'h'
int 21h
new_line
;*******************************************************************************************
;QUESTION #5
;print PSP,data,sseg & code addresses
mov base,16
mov sign,0
putstr msg5
mov dx,offset es
Print1 dx,base,sign
PHex
new_line
putstr msg6
mov dx,offset data
Print1 dx,base,sign
PHex
new_line
putstr msg7
mov dx,offset sseg
Print1 dx,base,sign
PHex
new_line
putstr msg8
mov dx,offset code
Print1 dx,base,sign
PHex
new_line
;*******************************************************************************************
;QUESTION #6
;sort array of signed & unsigned entered numbers
;create new array of 'Tab' as signed numbers
lea bx,Tab
mov si,0
mov cx,6
@MakeTabSigned:
mov ah,0
mov al,[bx]
add al,0
jns @IsPositive
neg al
cbw
neg ax
cmp ax,128
jne @IsPositive
cbw
@IsPositive:
mov TabSigned+si,ax
inc bx
add si,2
loop @MakeTabSigned
putstr msg9
;bubble sort of original 'Tab' array & printing it
mov cx,5
lea bx,Tab ;offset of specific 'tab'
mov sign,0
call BubbleSort
;print the sorted array
mov cx,6
mov base,10
mov di,0
@PrintUnsignedSortedArray:
mov al,[bx+di]
mov ah,0
push cx
push bx
Print1 ax,base,sign
pop bx
pop cx
mov ah,2
mov dx,';'
int 21h
inc di
loop @PrintUnsignedSortedArray
new_line
putstr msg10
;bubble sort of 'Tab' as signed array & printing it
mov cx,5
lea bx,TabSigned ;offset of specific 'tab'
mov sign,1
call BubbleSort
;print the sorted array
mov cx,6
mov base,10
mov di,0
@PrintSignedSortedArray:
mov ax,[bx+di]
push cx
push bx
Print1 ax,base,sign
pop bx
pop cx
mov ah,2
mov dx,';'
int 21h
add di,2
loop @PrintSignedSortedArray
new_line
;**************** END ***************
mov ah,4ch
int 21h
code ends
end start</code></pre>