section .data
numbers dw 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
count equ 10
section .text
global _start
_start:
mov cx, count
mov bx, 0 ; 最大数
mov ax, 0 ; 第二大数
loop_start:
cmp bx, [numbers + cx*2 - 2] ; 比较当前数和最大数
jg update_max ; 如果当前数大于最大数,更新最大数
cmp ax, [numbers + cx*2 - 2] ; 比较当前数和第二大数
jg update_second_max ; 如果当前数大于第二大数,更新第二大数
loop loop_start ; 继续循环
update_max:
mov ax, bx ; 更新第二大数为最大数
mov bx, [numbers + cx*2 - 2] ; 更新最大数为当前数
loop loop_start ; 继续循环
update_second_max:
mov ax, [numbers + cx*2 - 2] ; 更新第二大数为当前数
loop loop_start ; 继续循环
exit:
; 在这里可以使用ax寄存器中的值,即第二大数
; 可以将其存储到内存中或进行其他操作
mov eax, 1
xor ebx, ebx
int 0x80