對於彙編器我很新,我只需要完成我的學校任務,但是我有一個小問題。程序應該讀取輸入的兩位數字,並計算所有大於第一個數字的數字。問題是寄存器EDX(用於計數更大的數字)增加到1,但不超過它。你能提出一些不太複雜的東西嗎?彙編器x86中遞增寄存器的值不會高於1
%include "asm_io.inc"
segment .data
char_prompt db "Insert numbers: ",0
comma db ", ",0
out_msg1 db "Count of numbers greater than the first number(",0
out_msg2 db "): ",0
segment .text
global _asm_main
_asm_main:
enter 0,0
pusha
mov EAX, char_prompt
call print_string
first_number:
call read_char
cmp EAX, 32
je first_number
cmp EAX, 10
je after_input
cmp EAX, 13
je after_input
sub EAX, 48 ; turn ASCII code into a digit
mov EBX, 10
mul EBX ; multiply decimal point by 10
mov EBX, EAX
call read_char
sub EAX, 48 ; turn ASCII code into a digit
add EAX, EBX ; add decimals and units together
mov ECX, EAX
call print_int
mov EAX, comma
call print_string
jmp main_loop
main_loop:
call read_char
cmp EAX, 32
je main_loop
cmp EAX, 10
je after_input
cmp EAX, 13
je after_input
sub EAX, 48 ; turn ASCII code into a digit
mov EBX, 10
mul EBX ; multiply decimal point by 10
mov EBX, EAX
call read_char
sub EAX, 48 ; turn ASCII code into a digit
add EAX, EBX ; add decimals and units together
mov EBX, EAX
call print_int
mov EAX, comma
call print_string
mov EAX, EBX
cmp EAX, ECX ; compare current number to first number
ja increase
jmp main_loop
increase:
inc EDX ; increase count of greater numbers <-- PROBLEM HERE
jmp main_loop
after_input:
mov EAX, out_msg1
call print_string
mov EAX, ECX
call print_int
mov EAX, out_msg2
call print_string
mov EAX, EDX
call print_int
jmp finish
finish:
popa ; terminate program
mov EAX, 0
mov EBX, 0
mov ECX, 0
mov EDX, 0
leave
ret
輸出的格式還是非常原始的,我一旦解決了這個主要問題就會糾正它。
我也試過
add EDX, 1
,而不是
inc EDX
,但它是相同的結果。
如果有人幫助我,我會很感激。
逐行掃描調試器。你會看到在mul指令處發生了edx寄存器的一些事情。 –
我敢肯定,這兩個公司和添加工作得很好:)它,而地方看起來像你的代碼,EDX使用(你的子功能通常一個)。嘗試'推在你的循環的開始edx'權,'流行edx'你增加它之前 – Tommylee2k