Qbasicnews.com

Full Version: ASM code crashes with 'Illegal Operation'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
With this code:
Code:
;AsmTests.asm
;By Zack
;Tests different operations

.model small    ;64K Model
.stack 100h     ;100h bytes For the stack
.data   ;Start data segment
SWAP textequ <XCHG>    ;SWAP command is equiv to XCHG command
MsgTxt DB "AsmTests By Zachary Vernon",'$'     ;MsgTxt variable
.code   ;Start code segment
Msg proc       ;Procedure that displays message
    mov ax,@data        ;AX reg has adress of Data seg
    mov ds,ax           ;DS (data seg) reg has address of Data seg

    mov ah,9            ;AH has 9d, used for function 9 int 21h (print string)
    mov dx,offset MsgTxt       ;DX has addr/offset of MsgTxt
    int 21h     ;Call int 21h with DS:DX pointing to string to print (func 9)
Msg endp       ;End procedure

Math proc      ;Start proc that does math
    mov ax,0F000h  ;AX reg F000h
    add ax,0F00h  ;Add Fh to AX reg (now FF00h)
    sub ax,3000h  ;Subract 30h from AX reg (now CF00h)

    mov bx,0004h  ;BX now 04h
    dec bx      ;BX now 0003h
    inc bx      ;bx now 0004h
    inc bx      ;bx now 0005h
Math endp      ;End proc

XSwap proc     ;Start proc that uses the textequ XCHG-SWAP in data seg
    mov ax,00A8h  ;ax reg now 00A8h
    mov bx,3F00h  ;bx reg now 3Fh
    SWAP bx,ax  ;Swap (xchg) values in bx (3Fh) and ax (A8h).
XSwap endp

EndProg proc   ;Start proc that will end program with int 21h, func 4ch
    mov ax,4Ch  ;Ax now 4Ch
    int 21h     ;End prog, with int 21h, func 4Ch
EndProg endp
end EndProg
Something makes the program crash, giving me the ol' "Illegal Operation" message.
I can't figure out why it crashes...I wen't through it all.
NOTE: The info in the comments might be wrong...I think it's right though.
Oh, and some long lines of code are broken onto the next line...
Its not spamming if they're genunie questiosn, but it would be easier and a lot more helpful if you actually put some of the actual question as the subject. Reading 2 "another asm questions" could be seen to a moderator as 2 more to be deleted ;-) You can post valid quesitons without problems just call them something easier for people searching in the future.
Ok, wildcard :-)
I edited the post.
You're not quitting the program. that's why it crashes. And also, the service for printing text is 9h and not 9.
Code:
mov ah,4Ch      
int 21h

is missing at the end of your main proc.
.
Try this

Code:
.model small, c
            .386
            .stack 100h
                        
            .data
msga        db      "Message One", 13, 10, '$'
msgb        db      "Message Two", 13, 10, '$'

            .code
            assume ds:nothing, ss:nothing
            
            
;;;;
;;
;; Print a message terminated with $
;;
print       proc    private uses dx ds,\
                    pstr:far ptr

            lds     dx, pstr
            mov     ax, 0900h
            int     0021h  

            ret
print       endp    
        

;;;;
;;
;; Return to DOS
;;
system      proc    private

            mov     ax, 4c00h
            int     0021h
            
system      endp


;;;;
;;
;; Main
;;
main        proc    private

            invoke  print, addr msga
            invoke  print, addr msgb
            invoke  system
            
main        endp
            end main

Neat isn't it? It's like a high level language.
WOW :o definitely, I'll change to MASM and leave that horrid nightmare Turbo Assembler used to be Smile
thanx
Pages: 1 2