简体   繁体   中英

Asm program doesnt give output

still about that project i have, im trying to print an array and nothing happens... no errors or anything, the only thing that happens is that the user can enter 9 chars and that it, the program finishes the program needs to get 9 numbers between 0 and 9 and divide to groups a, b and c

MODEL small
STACK 100h
DATASEG
Welcome db "Welcome, please enter 9 numbers between 0 and 9: $"
MainArr db 9 dup(0)
Aarr db 9 dup(0)
Barr db 9 dup(0)
Carr db 9 dup(0)
AarrLength db ?
BarrLength db ?
CarrLength db ?
CODESEG
start:
mov ax, @data
mov ds, ax

mov dx, offset Welcome
mov ah, 9
int 21h
xor di, di
xor bx, bx
mov si, 0
mov cx, 0
jmp gettingInput
gettingInput:
inc cx
cmp cx, 10
je continue
mov ah, 1h
int 21h
mov [MainArr+si], al
inc si
cmp al, 8
jge zoneA
cmp al, 6
jb zoneC
jmp zoneB

zoneA: 
mov [Aarr+bx],al
inc bx
jmp gettingInput

zoneB: 
mov [Barr+si],al
inc si
jmp gettingInput

zoneC: 
mov [Carr+di],al
inc di
jmp gettingInput

continue:

mov cx, 9
xor ax, ax
mov si, offset Aarr
findLengthA:
cmp [si], 0
je foundLength
inc ax
loop findLengthA

foundLengthA:
mov [AarrLength], al 

mov cx, 9
xor ax, ax
mov si, offset Barr
findLengthB:
cmp [si], 0
je foundLength
inc ax
loop findLengthB

foundLengthB:
mov [BarrLength], al 


mov cx, 9
xor ax, ax
mov si, offset Carr
findLengthC:
cmp [si], 0
je foundLength
inc ax
loop findLengthC

foundLength:
mov [CarrLength], al 


mov bl, AarrLength
mov bh, 0
inc bx
inc bx
mov [offset Aarr + bx], '$'
mov si, offset Aarr
printA:
mov ah, 9h
mov dx, offset Aarr
int 21


exit:
mov ax, 4c00h
int 21h
END start

I suspect the problem lies in your zoneA, B, C regions. You seem to be relying on registers to hold the lengths of your arrays. I'd suggest you load and store the actual array length variables within each zone. You also use si in the main array, so I'm pretty sure that's a bug.

You forget that the input is a character. Yet you compare as if it were a small value!

mov ah, 1h
int 21h
mov [MainArr+si], al
inc si
cmp al, "8"      <--- Compare as character
jge zoneA
cmp al, "6"      <--- Compare as character
jb zoneC
jmp zoneB

Because of this error, all the data lands in the Aarr . Luckily as it turns out, because of the other errors!
Please note:

  • zoneA gets "8", "9"
  • zoneB gets "6", "7"
  • zoneC gets "0", "1", "2", "3", "4", "5"

This appears not to be what you wanted, looking at your previous question!!!


 je foundLength

In the A and B cases, you need to branch to foundLengthA and foundLengthB respectively.


You cannot use the SI register to address both the MainArr and the Barr at the same time!
Either use

  • variables like @AustinHastings suggested
  • or else use the BP register with an explicite segment override mov [ds:Barr+bp], al inc bp

There are multiple problems with the way you display the Aarr array. This is the correct way:

mov  bl, AarrLength
mov  bh, 0              <--- No need to use INC BX twice
mov  [Aarr + bx], '$'
mov  ah, 09h
mov  dx, offset Aarr
int  21h                <--- Don't forget the "h" for hexadecimal

In order to make sure that your search for the terminating zero in each of the 3 arrays is successful, make the storage 10 bytes. In the event that all 9 inputs go into the same array, you'll still find a terminating zero.

Aarr db 10 dup(0)
Barr db 10 dup(0)
Carr db 10 dup(0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM