6 Replies - 382 Views - Last Post: 23 August 2018 - 10:07 AM

#1 Day1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-August 18

I want to get my element after i enter my index, but it got error

Posted 18 August 2018 - 06:48 AM

.MODEL SMALL
.STACK 100
.DATA
	
		ARRA  DB "FIELD MAPLE$","WEET BIRCH$","BOXWOOD$","SILVER FIR$","EASTERN HEMLOCK$","LEBANON CEDAR$"
		ARRB  DB 20, 30, 20, 10, 30, 10
		MSG	  DB "YOUR SELECTION : $"	
		ONE   DB 1
		FT    DB 14
 
.CODE

MAIN PROC 
		MOV AX, @DATA
        MOV DS, AX
		
		LEA DX, MSG
		MOV AH, 09H
		INT 21H
		
		MOV AH, 01H
		INT 21H
		SUB AL, 30H
		MUL FT

		
		LEA DX, ARRA
		MOV DL, AL
		MOV AH, 09H
		INT 21H

		MOV AX, 4C00H
		INT 21H
		
MAIN ENDP
END MAIN 



so this is my output
YOUR SELECTION:1PLE //something like this but i want like when i enter 1 it will show the element in the index 1

Is This A Good Question/Topic? 0
  • +

Replies To: I want to get my element after i enter my index, but it got error

#2 Salem_c   User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2279
  • View blog
  • Posts: 4,362
  • Joined: 30-May 10

Re: I want to get my element after i enter my index, but it got error

Posted 18 August 2018 - 08:45 AM

> 24 MUL FT
All your strings need to be exactly 14 bytes in length.

If DB "FIELD MAPLE$" puts a \0 on the end, then you need to count that as well.

> 28 MOV DL, AL
You're assuming DL is zero. Perhaps you need to ADD the calculated offset to whatever your base address is.
Was This Post Helpful? 1
  • +
  • -

#3 Day1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-August 18

Re: I want to get my element after i enter my index, but it got error

Posted 18 August 2018 - 07:42 PM

so that mean is ADD DL, AL ?
Was This Post Helpful? 0
  • +
  • -

#4 Day1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-August 18

Re: I want to get my element after i enter my index, but it got error

Posted 18 August 2018 - 07:47 PM

.MODEL SMALL
.STACK 100
.DATA
	
		ARRA  DB "EASTERN HEMLOCK$"
			  DB "SILVER FIR     $"
			  DB "LEBANON CEDAR  $"
			  DB "FIELD MAPLE    $"
		      DB "WEET BIRCH     $"
			  DB "BOXWOOD        $"
			  
		ARRB  DB "60             $"
			  DB "40        	 $"
			  DB "50             $"
			  DB "10             $"
			  DB "20             $"
			  DB "30             $"
		MSG	  DB "YOUR SELECTION : $"	
		ONE   DB 1
		SIXT  DB 16
		TWO   DB 2
		MSG1  DB 13,10,"TIMBER CLASS : $"
		MSG2  DB 13,10,"PRICE PER KG : $"
		MSG3  DB 13,10,"QUANTITY     : $"
		MSG4  DB 13,10,"ESTIMAED WEIGHT : $"
		MSG5  DB 13,10,"TOTAL PRICE : $"
		A     DB ?
 
.CODE

MAIN PROC 
		MOV AX, @DATA
        MOV DS, AX
		
		LEA DX, MSG
		MOV AH, 09H
		INT 21H
	
		MOV AH, 01H
		INT 21H
		SUB AL, 30H
		SUB AL, ONE
		MUL SIXT 
		
		LEA DX, MSG1
		MOV AH, 09H
		INT 21H
		
		LEA DX, ARRA		;this will output arrayA element afer the user enter index 
		ADD DL, AL
		MOV AH, 09H
		INT 21H
		
		LEA DX, MSG2	
		MOV AH, 09H
		INT 21H
		
		LEA DX, ARRB		;this will output arrayB element but after index 2 the element does not show up why ?
		ADD DL, AL
		MOV AH, 09H
		INT 21H
			
		LEA BX, ARRB
		
		LEA DX, MSG3    ;PROMPT USER TO ENTER QUANTITY
		MOV AH, 09H
		INT 21H
		
		MOV AH, 01H
		INT 21H
		SUB AL, 30H
		MOV CX, [BX]
		MUL CL
		
	
		
		
		
		
		MOV AX, 4C00H
		INT 21H
		
MAIN ENDP
END MAIN 


//so now i have a new problem that is now i able to get my element of arrA but unable to get my element at arrB after the index 2. ca help me to see what is the problem
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is offline

  • dependency injected
  • member icon

Reputation: 6668
  • View blog
  • Posts: 27,305
  • Joined: 12-December 12

Re: I want to get my element after i enter my index, but it got error

Posted 19 August 2018 - 12:44 AM

Moved to Assembly forum.
Was This Post Helpful? 0
  • +
  • -

#6 Salem_c   User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2279
  • View blog
  • Posts: 4,362
  • Joined: 30-May 10

Re: I want to get my element after i enter my index, but it got error

Posted 19 August 2018 - 04:42 AM

Whereas you previously assumed that a simple MOV was needed where you in fact needed an ADD, now you're assuming that your ADD doesn't overflow a byte.

Do you have any kind of debugger to hand, you know something that allows you to single step the code one instruction at a time and allows you to inspect the state of memory and registers.

After each instruction, you look at the relevant memory and registers and figure out whether what actually happened matched your expectation. When these two things are not the same, you've found a bug.
Was This Post Helpful? 0
  • +
  • -

#7 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,096
  • Joined: 03-April 12

Re: I want to get my element after i enter my index, but it got error

Posted 23 August 2018 - 10:07 AM

Also, are you sure that AL is preserved in DOS calls?

AH = 09h - WRITE STRING TO STANDARD OUTPUT

Entry: DS:DX -> '$'-terminated string

Return: AL = 24h
http://spike.scu.edu...rupts.html#ah09

Maybe it just prints the last 12 blanks of
DB "50             $"

This post has been edited by turboscrew: 23 August 2018 - 10:08 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1