tasm : Relative jump out of range by 0020h bytes
I had been trying to write a basic com file for a 'shell'. I was able to assemble the same code in NASM with little modifications.
However this code won't assemble in TASM ! I get errors of the kind : Relative jump out of range I looked up a little on Google to find out about jumps. However I could not find much, except the idea to break this jump into relatively shorter jumps. Is there be a neater alternative ?
Here's the code :
.model tiny
CR equ 13d
LF equ 10d
TAB equ 09d
.data
prompt db CR,LF,"Input : ",0
tab_max db 7 dup('_'),0
input db 128 dup(0) ; Input Buffer Of 80 Bytes
str_ver db CR,LF,CR,LF,CR," ",\
"Version : 1.0",CR,LF,0
str_help db CR,LF,CR,LF,CR," ",\
"Type VER For Version !!!",\
CR,LF,CR," ",\
"Type CLS To Clear Screen !!!",\
CR,LF,CR," ",\
"Type HELP To Display This Message !!!",\
CR,LF,0
str_welcome db "Welcome To My Operating System !!!",0
str_default db CR,LF,CR,LF,CR," ",\
"Invalid Command !!!",\
CR,LF,CR," ",\
"Type HELP To Display Help !!!",\
CR,LF,0
cmd_ver db "VER",0
cmd_help db "HELP",0
cmd_cls db "CLS",0
.code
org 100h
main proc near
xor ax,ax ; Select Video Mode Function
mov al, 03h ; Select 80x25 (8 Pages) Text Mode
int 10h ; Call Interrupt
mov dh, 0h ; Row
mov dl, 0h ; Column
call goto_xy
mov cx, 30h
lea si, [str_welcome]
call put_str
Begin0:
lea si, [prompt] ; Display Prompt
mov cx, 0ah ; Max Length=10
call put_str
call beep
lea si, [input]
call null_str ; Recycle The Input Buffer
mov cx, 60h ; Max Length=64
call get_str ; Read User Input
call del_whitespace ; Do Away With Leading And Trailing Space Characters
call str_to_upper ; Convert To Uppercase
call chk_internal ; Cross-Check In Internal Commands
jmp Begin0 ; Loop Forever
endp
null_str proc near
push si ; Save SI
push cx ; Save CX
push ax ; Save AX
xor ax, ax
call str_len ; Move Length Of String In CX
.more0:
cmp cx, 0 ; Is It Zero-Length ?
jz .finish0 ; If So Do Away With
mov [si], ax ; Null A Character In Input Buffer
dec cx ; Decrement Counter
inc si ; Advance SI
jmp .more0 ; Loop On Until First 0
.finish0:
pop ax ; Retrieve AX
pop cx ; Retrieve BX
pop si ; Retrieve SI
ret ; Return
endp
del_whitespace proc near
push si ; Save SI
push di ; Save DI
push dx ; Save DX
push cx ; Save CX
push bx ; Save BX
push ax ; Save AX
xor ax, ax
xor bx, bx
xor cx, cx
xor dx, dx
mov di, si
dec si ; SI=SI-1
.loop00:
inc si ; Go On Incrementing Source String Index
xor dx, dx
mov dx, [si]
xor dh, dh
cmp dl, 00h ; Is String Finished ?
jz .chomp00
cmp dl, 20h ; Is It A Space
jz .loop00 ; Go On Eating
I had been trying to write a basic com file for a 'shell'. I was able to assemble the same code in NASM with little modifications.
However this code won't assemble in TASM ! I get errors of the kind : Relative jump out of range I looked up a little on Google to find out about jumps. However I could not find much, except the idea to break this jump into relatively shorter jumps. Is there be a neater alternative ?
Here's the code :
.model tiny
CR equ 13d
LF equ 10d
TAB equ 09d
.data
prompt db CR,LF,"Input : ",0
tab_max db 7 dup('_'),0
input db 128 dup(0) ; Input Buffer Of 80 Bytes
str_ver db CR,LF,CR,LF,CR," ",\
"Version : 1.0",CR,LF,0
str_help db CR,LF,CR,LF,CR," ",\
"Type VER For Version !!!",\
CR,LF,CR," ",\
"Type CLS To Clear Screen !!!",\
CR,LF,CR," ",\
"Type HELP To Display This Message !!!",\
CR,LF,0
str_welcome db "Welcome To My Operating System !!!",0
str_default db CR,LF,CR,LF,CR," ",\
"Invalid Command !!!",\
CR,LF,CR," ",\
"Type HELP To Display Help !!!",\
CR,LF,0
cmd_ver db "VER",0
cmd_help db "HELP",0
cmd_cls db "CLS",0
.code
org 100h
main proc near
xor ax,ax ; Select Video Mode Function
mov al, 03h ; Select 80x25 (8 Pages) Text Mode
int 10h ; Call Interrupt
mov dh, 0h ; Row
mov dl, 0h ; Column
call goto_xy
mov cx, 30h
lea si, [str_welcome]
call put_str
Begin0:
lea si, [prompt] ; Display Prompt
mov cx, 0ah ; Max Length=10
call put_str
call beep
lea si, [input]
call null_str ; Recycle The Input Buffer
mov cx, 60h ; Max Length=64
call get_str ; Read User Input
call del_whitespace ; Do Away With Leading And Trailing Space Characters
call str_to_upper ; Convert To Uppercase
call chk_internal ; Cross-Check In Internal Commands
jmp Begin0 ; Loop Forever
endp
null_str proc near
push si ; Save SI
push cx ; Save CX
push ax ; Save AX
xor ax, ax
call str_len ; Move Length Of String In CX
.more0:
cmp cx, 0 ; Is It Zero-Length ?
jz .finish0 ; If So Do Away With
mov [si], ax ; Null A Character In Input Buffer
dec cx ; Decrement Counter
inc si ; Advance SI
jmp .more0 ; Loop On Until First 0
.finish0:
pop ax ; Retrieve AX
pop cx ; Retrieve BX
pop si ; Retrieve SI
ret ; Return
endp
del_whitespace proc near
push si ; Save SI
push di ; Save DI
push dx ; Save DX
push cx ; Save CX
push bx ; Save BX
push ax ; Save AX
xor ax, ax
xor bx, bx
xor cx, cx
xor dx, dx
mov di, si
dec si ; SI=SI-1
.loop00:
inc si ; Go On Incrementing Source String Index
xor dx, dx
mov dx, [si]
xor dh, dh
cmp dl, 00h ; Is String Finished ?
jz .chomp00
cmp dl, 20h ; Is It A Space
jz .loop00 ; Go On Eating
No comments:
Post a Comment