Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Relative jump out of range Error - Assembly Language

Status
Not open for further replies.

asgard1118

Programmer
Sep 15, 2019
1
0
0
PH
Hello Everyone!!
Just need some assistance on my error, really can't figure out how to fix this. I have errors on lines 88,90,and 92.Please, please please

.MODEL small
.STACK 100h

.DATA
m0 db " ******JOLLIJEEP FAST FOOD******$"
prompt1 db 10,13,'Please enter your Name:$'
greet db 10,13,'Hello, $'
crlf db 10,13,'$'
m1 db 10,13,'What would you like to order:$'
m2 db 10,13,"1.Burger 50/- 2.Spaghetti 30/- 3.Chicken 60/- $"
m3 db 10,13,'Please enter your choice number:$'
m4 db 10,13,'To add press 1 or Press 2 to get back menu:$'
m5 db 10,13,'Enter quantity:$'
m6 db 10,13,"Total price: $"
m7 db 10,13," ====THANK YOU====$"
m8 db 10,13,"SORRY!There is no more than 3 items,if u want,u can add one$"
m9 db 10,13,"Enter Food name:$"
m10 db 10,13," Price:$"
m11 db "4.$"
m12 db "/-$"
m13 db 10,13," Re-odrer : Press <1>$"
m14 db 10,13," Exit : Press Any key$"

.data?
string db 80 dup(?)
var1 db 100 dup('$')
v db 0
q dw 0
r dw 0
s dw 0
rprice dw 50
vprice dw 30
sprice dw 60
nprice dw 0

WriteSt MACRO MessLab
push ax
push dx
mov ah,9
mov dx,offset MessLab
int 21h
pop dx
pop ax
ENDM

.CODE
MAIN PROC
mov ax, @DATA
mov ds, ax

DisplayPrompt:
Writest crlf
WriteSt m0
Writest crlf
WriteSt prompt1 ;Display prompt1
lea SI, string ;Load string into SI
Call ReadString ;Get info from keyboard
WriteSt greet
WriteSt string
WriteSt crlf
mov ax, 4C00h ;# Exit to dos
jmp Start

Start: ;start
cmp v,0
jg start1

mov ah,9
Lea dx,m1
int 21h

Menu:

mov ah,9
Lea dx,m2
int 21h

mov ah,9
Lea dx,m3
int 21h

mov ah,1
int 21h

cmp al,31h
je Bur ;ERROR relative jumpout of range by 0013h bytes
cmp al,32h
je Spag ;ERROR relative jumpout of range by 0024h bytes
cmp al,33h
je Chic ;ERROR relative jumpout of range by 0035h bytes

Menuadd:
inc v

mov ah,9
Lea dx,m8
int 21h

mov ah,9
Lea dx,m4
int 21h

mov ah,1
int 21h
cmp al,32h
je menu

mov ah,9
Lea dx,m9
int 21h

mov si,offset var1

l1:
mov ah,1
int 21h
cmp al,13
je print
mov [si],al
inc si
jmp l1

print:

call price

start1:

mov ah,9
Lea dx,m2
int 21h

mov ah,9
Lea dx,m11
int 21h

mov dx,offset var1
mov ah,9
int 21h

mov ah,2
mov dl,' '
int 21h

xor ax,ax
mov ax,nprice
call outdec

mov ah,9
Lea dx,m12
int 21h



mov ah,9
Lea dx,m3
int 21h

mov ah,1
int 21h

cmp al,31h
je Bur
cmp al,32h
je Spag
cmp al,33h
je Chic

newmenu_:

mov ah,9
Lea dx,m5
int 21h

xor ax,ax

call indec

mul nprice

mov bx,ax

jmp totalprice



Bur:

mov ah,9
Lea dx,m5
int 21h

xor ax,ax
call indec
mul vprice
mov bx,ax
jmp totalprice

Spag:

mov ah,9
Lea dx,m5
int 21h

xor ax,ax
call indec
mul rprice
mov bx,ax
jmp totalprice

Chic:
mov ah,9
Lea dx,m5
int 21h

xor ax,ax
call indec
mul sprice
mov bx,ax
jmp totalprice

price:

mov ah,9
Lea dx,m10
int 21h

mov ax,0
mov bx,0
mov cx,0
mov dx,0

input:
and ax,000Fh
push ax
mov ax,10
mul bx
mov bx,ax
pop ax
add bx,ax

mov ah,1
int 21h

cmp al,0Dh
jne input

add nprice,bx
ret



totalprice:

mov ah,9
Lea dx,m6
int 21h

xor ax,ax


mov ax,bx
call outdec

mov ah,9
Lea dx,m13
int 21h

mov ah,9
Lea dx,m14
int 21h

mov ah,1
int 21h

cmp al,31h
je start

mov ah,9
Lea dx,m7
int 21h


mov ah,4ch
int 21h


MAIN ENDP

ReadString PROC NEAR
mov cx, si ; cx == buffer start address
Read:
mov ah,01h
int 21h ;Read 1 character
cmp al,13 ;Is it return?
je Done ;Yes, we are done reading in characters
mov [si],al ;No, move character into buffer
inc si ;Increase pointer
jmp Read ;loop back
Done:
mov [si], "$" ; terminate string
mov ax, si ; ax == buffer end address
sub ax, cx ; return characters read in ax
ret
Readstring ENDP

INDEC PROC NEAR
PUSH BX
PUSH CX
PUSH DX
BEGIN:

MOV AH, 2
MOV DL, ' '
INT 21H

XOR BX, BX
XOR CX, CX

MOV AH, 1
INT 21H

CMP AL, '-'
JE MINUS

CMP AL, '+'
JE PLUS
JMP REPEAT2

MINUS:
MOV CX, 1
PLUS:
INT 21H

REPEAT2:

CMP AL, '0'
JNGE NOT_DIGIT
CMP AL, '9'
JNLE NOT_DIGIT

AND AX, 000FH
PUSH AX

MOV AX,10
MUL BX
POP BX
ADD BX, AX

MOV AH, 1
INT 21H
CMP AL, 0DH
JNE REPEAT2

MOV AX, BX
OR CX, CX

JE EXIT
NEG AX

EXIT:

POP DX
POP CX
POP BX
RET

NOT_DIGIT:

MOV AH, 2
MOV DL, 0DH
INT 21H
MOV DL, 0AH
INT 21H
JMP BEGIN
INDEC ENDP

OUTDEC PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX

OR AX, AX
JGE END_IF1

PUSH AX
MOV DL, ' '
MOV AH, 2
INT 21H
POP AX
NEG AX

END_IF1:

XOR CX, CX
MOV BX, 10D

REPEAT1:

XOR DX, DX
DIV BX
PUSH DX
INC CX


OR AX, AX
JNE REPEAT1

MOV AH, 2

PRINT_LOOP:

POP DX
OR DL, 30H
INT 21H
LOOP PRINT_LOOP

POP DX
POP CX
POP BX
POP AX

RET
OUTDEC ENDP

end MAIN
 
Caveat i have never done any X86 Assebly programming so this is from basic principles

you are trying to branch too far in your code so either:-
1
move the code after the branch into a subroutine that you can call to reduce the length of the branch​
2
Invert the test so that you step over a jump to the ode required.​



Do things on the cheap & it will cost you dear
 
It has been a great number of years since I have done any assembly programming (say Commodore 64), but if I recall correctly a branch, goto, etc. has to be within 255 bytes.
 
for a 6502 (8 bit) processer branches were +127 -128 bytes. jumbs & jump subroutines were absolute addreses.

if you needed to branch more than the max distance you would simply invert the test (EG BNE instead of BEQ) and branch over jump.
I have no idea what the limitations are for the OP as he has not specified the cpu but wol assume the same principal should apply.




Do things on the cheap & it will cost you dear
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top