CSC231 Homework 7 Solution Programs 2014
--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