kwb
07-11-2010, 17:32
Ciao, ho fatto un programma che, preso in input un vettore di numeri, mi determina e stampa il maggiore, questo è ciò che ho scritto:
;You are asked to develop an 8086 assembly program that find the maximum
;element of a 10 elements unsigned 8 bits integer vector
.MODEL small
.STACK
DIM EQU 10
.DATA
VETT DB DIM DUP (?)
.CODE
.STARTUP
;Read Vector
MOV CX, DIM
MOV AH, 1 ;Prepare for getting input
MOV DI,0 ;Clear the index register
vRead: INT 21H
MOV VETT[DI], AL ;Move the DI-th element from AL to VETT
INC DI
LOOP vRead ;LOOP decrements CX of 1 then
;if ( CX != 0 ) goto vRead
;else parse next instruction
MOV CX, DIM ;Set the original dimension of the vector in CX
MOV DI, 0 ;Set DI back to 0
MOV AL, 0
compare: CMP VETT[DI],AL
JA maximum ;if (destination > source ) goto maximum
INC DI
CMP CX, DI ;if (CX != DI) goto compare
JNZ compare
maximum: MOV AL,VETT[DI]
INC DI
CMP CX,DI ;if ( DI != CX ) goto compare
JNZ compare
MOV AH,2 ;Set AH to 2 so that we can print to screen
INT 21H
.EXIT
END
Ho provato a fare il debug, e sembra funzionare correttamente, infatti DL si prende i giusti risultati...
Tuttavia mi domandavo una cosa... Questo programma prende 1 solo carattere... Quindi io non posso ad esempio fare un confronto tra numeri che vanno oltre il 9...
Come devo fare?
Inoltre...
Quando mi viene la schermata di input, io digito:
0 1 2 3 4 5 6 7 8 9
Però non ho capito se ciò che ho digitato sono gli effettivi numeri oppure dei caratteri ascii...
Cioè, nel vettore io ho caricato dei numeri oppure:
NULL SOH STX ETX EOT ENQ ACK BEL BS TAB
Ovvero i corrispettivi simboli?
Per capirci, per fargli prendere dei numeri ( facciamo, per semplicità per ora, da 0 a 9 ) devo digitare i loro caratteri ascii ( quindi i numeri dal 48 al 57 inclusi)?
EDIT:
Di questo programma ho la soluzione, ma è molto più complessa rispetto alla mia...
;You are asked to develop an 8086 assembly program that find the maximum
;element of a 10 elements unsigned 8 bits integer vector
.MODEL small
.STACK
DIM EQU 10
.DATA
VETT DB DIM DUP (?)
.CODE
.STARTUP
;Read Vector
MOV CX, DIM
MOV AH, 1 ;Prepare for getting input
MOV DI,0 ;Clear the index register
vRead: INT 21H
MOV VETT[DI], AL ;Move the DI-th element from AL to VETT
INC DI
LOOP vRead ;LOOP decrements CX of 1 then
;if ( CX != 0 ) goto vRead
;else parse next instruction
MOV CX, DIM ;Set the original dimension of the vector in CX
MOV DI, 0 ;Set DI back to 0
MOV AL, 0
compare: CMP VETT[DI],AL
JA maximum ;if (destination > source ) goto maximum
INC DI
CMP CX, DI ;if (CX != DI) goto compare
JNZ compare
maximum: MOV AL,VETT[DI]
INC DI
CMP CX,DI ;if ( DI != CX ) goto compare
JNZ compare
MOV AH,2 ;Set AH to 2 so that we can print to screen
INT 21H
.EXIT
END
Ho provato a fare il debug, e sembra funzionare correttamente, infatti DL si prende i giusti risultati...
Tuttavia mi domandavo una cosa... Questo programma prende 1 solo carattere... Quindi io non posso ad esempio fare un confronto tra numeri che vanno oltre il 9...
Come devo fare?
Inoltre...
Quando mi viene la schermata di input, io digito:
0 1 2 3 4 5 6 7 8 9
Però non ho capito se ciò che ho digitato sono gli effettivi numeri oppure dei caratteri ascii...
Cioè, nel vettore io ho caricato dei numeri oppure:
NULL SOH STX ETX EOT ENQ ACK BEL BS TAB
Ovvero i corrispettivi simboli?
Per capirci, per fargli prendere dei numeri ( facciamo, per semplicità per ora, da 0 a 9 ) devo digitare i loro caratteri ascii ( quindi i numeri dal 48 al 57 inclusi)?
EDIT:
Di questo programma ho la soluzione, ma è molto più complessa rispetto alla mia...