Saturday, 15 January 2011

assembly - How to compare 2 number? -



assembly - How to compare 2 number? -

i writing programme compare 2 numbers have been defined in info segment. define them this

dseg segment para public 'data' num1 dw 1 ; num1 = 1 num2 dw 2 ; num2 = 2 max dw ? ; variable save max number min dw ? ; variable save min number dseg ends cseg segment para public 'code' assume cs : cseg , ds : dseg , ss : sseg , es : nil org 100h mov ax , dseg mov ds , ax mov ax , num1 ; move num1 ax cmp ax , num2 ; compare num1 num2 jae max1 ; jump if num1 > num2 mov ax , num2; ax = num2 mov max , ax ; max = ax mov ax , num1; ax = num1 mov min , ax ; min = ax jmp endprog max1 : mov ax , num1; ax = num1 mov max , ax ; max = ax mov ax , num2; ax = num2 mov min , ax ; min = ax jmp endprog endprog : ;.............. mov ax , 4c00h int 21h cseg ends end

but jump orders not work well! , stuck @ endprog label. want know why that? wrong code?

mov ax, num1 loads ax address of num1. should utilize mov ax, [num1], , same other operations access variables.

assembly

No comments:

Post a Comment