What is the difference between printing signed and unsigned number in assembly (80x86)? -
i have task take existing assembly program prints signed number (word sized), , need change print unsigned numbers (word sized)... please me understand difference , how should accomplish this.
that program prints signed number:
.model small .stack 100h .data num dw -32768 nums db 6 dup(' '),'$' .code mov ax, @data mov ds, ax mov ax, num mov bx, 10 mov si, offset nums+5 next: cwd idiv bx cmp dx, 0 jge cont neg dx cont: add dl, 48 mov [si], dl dec si cmp ax, 0 jz sof jmp next sof: cmp num, 0 jge soff mov byte ptr[si], '-' soff: mov ah, 9 mov dx, si int 21h .exit end
thanks!
since word size 16 bits, range of signed numbers -32768 32767, range unsigned numbers goes 0 65535. , while you're declaring num -32768, computer represents in hex 0x8000, if it's performing signed operations -32768, if performing unsigned operations +32768.
if use different negative number, -1, 0xffff in hex. if perform unsigned operation on it, interpreted 65535.
note idiv instruction signed division, whereas div instruction unsigned.
Comments
Post a Comment