找到存储在整数数组中的最大整数(assembly nasm)

时间:2015-04-14 00:52:32

标签: assembly nasm

我正在尝试找到此数组中的最大数字。我在第10,11,12,14,17行“在16位模式下不支持指令”时收到错误。我对集会很新,而且我被困住了。请指出我正确的方向或告诉我我做错了什么!感谢

我正在尝试在ubuntu中使用nasm编译器。请告诉我是否有更好的方式

section .data   
    num: dw  0x1,0x2, 0x4, 0xFF, 0xFE, 0xFA, 0x7, 0x9, 0x8, 0xFD
    .length: equ $-num
    max: dw 0

section .text
    global _start

_start:
   mov       rbx, num.length          ; size in bytes of numbers
   shr       rbx, 1                   ; divided by two (2 bytes in one word) gives number of integers
   mov       rsi, num                 ; start of integer list
   cld                                ; D flag should be zero, make zero just to be sure
   mov       rcx, rbx                 ; move number of integers in RCX (= loop counter)
repeat:
   lodsw                              ; load word in ax
   cmp       rcx, rbx                 ; is it first number in list?
   je        firstMax                 ; yes, min and max are both the same at this point
   cmp       ax, word[max]            ; not the first number in the list compare with maximum
   jg        newMax                   ; if greater than current max then ax has new maximum (use jg for signed integers else use ja)
   cmp       ax, word[min]            ; not greater, lower perhaps?
   jl        newMin                   ; yes, ax has new minimum (use jl for signed integers else use jb)
next:
    loop      repeat                   ; if RCX isn't zero then there are more integers in the list, so repeat loop
    jmp       Exit                     ; otherwise we exit the program, WORD[min] has minimum from list, WORD[max] has the maximum from the list
firstMinMax:                         ;
   mov       word[max], ax            ; store first max
newMax:
   mov       word[max], ax            ; store (new or first) maximum
   jmp       next                     ; check for next integer
newMin:
   mov       word[min], ax            ; store new minimum
   jmp       next                     ; check for next integer

Exit:

0 个答案:

没有答案