Feb 10, 2011

Assembly macro - Some useful stuffs

Hello :)

After running through the nuisance of printing output and debugging, I have came up with these macro. It might be useful for you somehow :)

All bug free :) I hope the code is self-explained. But if there are any errors or things you want to add, please leave a comments :)

    ;useful macro call
    ;make new line: printChar 10 printChar 13
    ;add a break point in your code that stop TurboDebugger when you hit F9: addBreakPoint

    addBreakPoint macro
        ;save register
        push AX
  
        pushf                                                        ;AX=PSW
        pop AX                                                   ;
       
        or AX,0100h                                           ;set 8th bit (trap flag)
       
        push AX                                                  ;PSW=AX
        popf                                                         ;
       
        ;restore register
        pop AX
    endm

    printChar macro    character                        ;print a character
    ;save register
        push DX
        push AX
                   
        mov DL, character                                    ;
        mov AH, 02h                                    ;
        int 21h                                        ;
       
        ;restore register
        pop AX
        pop DX
    endm
   
    printMsg macro msgString                        ;print a message
        ;save register
        push DX
        push AX
                                   
        mov DX, offset msgString                    ;print q1_1 string
        mov AH, 09h                                    ;
        int 21h                                        ;           
       
        ;restore register
        pop AX
        pop DX
    endm
Some quick thing to note:
  • I tried doing CMP with 8-bit register and use the "less than" jump command, but it does not turn out as expected. Instead, JL only works when CMP is called for 2 16-bit register.

No comments:

Post a Comment