CSC231 Homework 7 Solution Programs 2014

From dftwiki3
Revision as of 21:32, 30 November 2014 by Thiebaut (talk | contribs) (Created page with "--~~~~ ---- =Problem #1= <br /> <source lang="java"> global _printInt extern _printDec section .data minus db "-" section .t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

--D. Thiebaut (talk) 21:32, 30 November 2014 (EST)


Problem #1


        global  _printInt
extern  _printDec
        
        section .data
minus   db      "-"
        
        section .text
        global  _printInt
_printInt:
        pushad
        cmp     eax, 0
        jge     .positive

.negative:
        ;; save original number
        push    eax
        ;; print a '-' sign first
        mov     eax, 4
        mov     ebx, 1
        mov     ecx, minus
        mov     edx, 1
        int     0x80

        ;; get original number and make it positive
        pop     eax
        neg     eax
        
.positive:
        call    _printDec
        popad
        ret


Problem #2


        global  _printInt
extern  _printDec
        
        section .data
minus   db      "-"
        
        section .text
        global  _printInt16
_printInt16:
        pushad
        cwde                    ;extends ax into eax
        cmp     eax, 0
        jge     .positive

.negative:
        ;; save original number
        push    eax
        ;; print a '-' sign first
        mov     eax, 4
        mov     ebx, 1
        mov     ecx, minus
        mov     edx, 1
        int     0x80

        ;; get original number and make it positive
        pop     eax
        neg     eax
        
.positive:
        call    _printDec
        popad
        ret