汇编:如何将十六进制输入转换为十进制?(Assembly: How to convert hex input to decimal?)
我在这个问题上找到了很多问题,但是,我无法运行我的代码。 我的程序应采用十六进制值,检查它是否是一个有效的十六进制字符,然后将十六进制值显示为十进制值。 如果它是小写十六进制字符,则需要将其转换为大写。 所有这些都需要循环。
除了将十六进制转换为十进制之外,我完成了所有这些操作。 我有程序中的代码我认为应该转换它,但它不会编译。 我将列出代码下面的编译器错误。 如果标签convert:中的代码被注释掉(除了最后一行,“jmp display”),程序将按原样运行,但显然不会将值显示为小数。
用nasme编译:“nasm -fbin getChar.asm -o getChar.com -l getChar.lst”
我在dosbox中运行程序。
; This program gets a char from user and prints it out as a decimal org 100h ; program start point section .data msgIn: DB 13, 10, "Enter a Hex Digit: $" msgOut: DB 13, 10, "Decimal Value: $" msgOpt: DB 13, 10, "Enter another?(y or n): $" errMsg: DB 13, 10, "Illegal character, Enter 0..9 or A..F: $" HNUM: DB 19H NUM: DB 0 D: DB 10h H: DB 16 CNT: DB 0 section .text continue: ; start of loop mov dx, msgIn ; offset address of message to display mov ah, 9 ; print string function int 21h mov ah, 1 ; keyboard input sub-program int 21h ; read character into al mov cl, al legal: ; compare input to see if valid cmp cl, 48 ; cl < 0 jl end_if ; yes, error msg cmp cl, 70 ; cl > F jg check_case ; yes, error msg jmp prntMsg2 ; print value of input check_case: ; check case of input cmp cl, 97 ; cl < a jl end_if ; yes, error msg cmp cl, 102 ; cl > f jg end_if ; yes, error msg jmp to_upper ; need to send to function to convert to upper case ; then pass to prntMsg2 to_upper: and al, 223 ; convert to upper case(0DFh) jmp prntMsg2 end_if: ; error message if invalid input mov ah, 9 mov dx, errMsg ; print error message int 21h jmp continue ; get a new value prntMsg2: ; print second message***** mov dx, msgOut ; offset of second message mov ah, 9 ; print string function int 21h ; display message convert: mov cx, 00 mov dx, 00 L6: mov ax, 00 mov al, [HNUM] div word [D] mov [HNUM], al mov bx, ax mov cl, 0 mov ax, 1 L5: cmp cl, 00 je L7 mul word [H] sub cl, 1 jmp L5 L7: mul bh add dx, ax add word [CNT], 1 cmp word [HNUM], 0 jg L6 mov [NUM], dl jmp display display: ; display character mov dl, al mov ah, 2 ; print char function int 21h mov ah, 9 ; see if user wants to do it again mov dx, msgOpt int 21h mov ah, 1 int 21h mov bl, al cmp bl, 'y' ; bl = y jne exitPrg ; no, end jmp continue ; get a new value exitPrg: ; exit program mov ah, 4ch ; exit to DOS function int 21h ; see you later!
上面的代码已经过编辑,现在可以编译和运行。 但是,它仍然没有正确地从十六进制转换为十进制。 它根本不显示值,只是空白。 如果输入一封信,即使是字母af,它也会挂断。 数字不会挂起,但仍不显示值。
现在我已经运行至少我可以修复它,但是,任何指导都表示赞赏。 感谢Gene让我开始运行。
I have found many questions on this issue, however, I have not been able to get my code to run. My program should take a hex value, check to see if it is a valid hex character, then display the hex value as a decimal value. If it is a lower case hex character then it needs to be converted to upper case. All this needs to be in a loop.
I have all of this done except for converting the hex to decimal. I have the code in the program I think should convert it, but it will not compile. I will list the compiler errors below the code. If the code in the label convert: is commented out(except for the last line, "jmp display") then the program will run as it should, but obviously will not show the value as a decimal.
Compiling with nasme: "nasm -fbin getChar.asm -o getChar.com -l getChar.lst"
I am running the program in dosbox.
; This program gets a char from user and prints it out as a decimal org 100h ; program start point section .data msgIn: DB 13, 10, "Enter a Hex Digit: $" msgOut: DB 13, 10, "Decimal Value: $" msgOpt: DB 13, 10, "Enter another?(y or n): $" errMsg: DB 13, 10, "Illegal character, Enter 0..9 or A..F: $" HNUM: DB 19H NUM: DB 0 D: DB 10h H: DB 16 CNT: DB 0 section .text continue: ; start of loop mov dx, msgIn ; offset address of message to display mov ah, 9 ; print string function int 21h mov ah, 1 ; keyboard input sub-program int 21h ; read character into al mov cl, al legal: ; compare input to see if valid cmp cl, 48 ; cl < 0 jl end_if ; yes, error msg cmp cl, 70 ; cl > F jg check_case ; yes, error msg jmp prntMsg2 ; print value of input check_case: ; check case of input cmp cl, 97 ; cl < a jl end_if ; yes, error msg cmp cl, 102 ; cl > f jg end_if ; yes, error msg jmp to_upper ; need to send to function to convert to upper case ; then pass to prntMsg2 to_upper: and al, 223 ; convert to upper case(0DFh) jmp prntMsg2 end_if: ; error message if invalid input mov ah, 9 mov dx, errMsg ; print error message int 21h jmp continue ; get a new value prntMsg2: ; print second message***** mov dx, msgOut ; offset of second message mov ah, 9 ; print string function int 21h ; display message convert: mov cx, 00 mov dx, 00 L6: mov ax, 00 mov al, [HNUM] div word [D] mov [HNUM], al mov bx, ax mov cl, 0 mov ax, 1 L5: cmp cl, 00 je L7 mul word [H] sub cl, 1 jmp L5 L7: mul bh add dx, ax add word [CNT], 1 cmp word [HNUM], 0 jg L6 mov [NUM], dl jmp display display: ; display character mov dl, al mov ah, 2 ; print char function int 21h mov ah, 9 ; see if user wants to do it again mov dx, msgOpt int 21h mov ah, 1 int 21h mov bl, al cmp bl, 'y' ; bl = y jne exitPrg ; no, end jmp continue ; get a new value exitPrg: ; exit program mov ah, 4ch ; exit to DOS function int 21h ; see you later!
The code above has been edited and now compiles and runs. However, it is still not doing the conversion from hex to decimal correctly. It simply doesn't display a value, just blank. It will also hang up if a letter is entered, even a letter a-f. A number does not hang it up, but still a value is not displayed.
Now that I have it running at least I can work on fixing it, however, any guidance is appreciated. Thanks Gene for getting me up and running.
原文:https://stackoverflow.com/questions/21870702
最满意答案
delete from a where id not in ( select * from ( select a.id from ab join a on (ab.a=a.id) join b on (ab.b=b.id) where a.pid=b.pid ) x ); delete from b where id not in ( select * from ( select b.id from ab join a on (ab.a=a.id) join b on (ab.b=b.id) where a.pid=b.pid ) x ); delete ab from ab left join a on ab.a = a.id left join b on ab.b = b.id where a.pid <> b.pid or a.id is null or b.id is null;
SQLFiddle演示
delete from a where id not in ( select * from ( select a.id from ab join a on (ab.a=a.id) join b on (ab.b=b.id) where a.pid=b.pid ) x ); delete from b where id not in ( select * from ( select b.id from ab join a on (ab.a=a.id) join b on (ab.b=b.id) where a.pid=b.pid ) x ); delete ab from ab left join a on ab.a = a.id left join b on ab.b = b.id where a.pid <> b.pid or a.id is null or b.id is null;
SQLFiddle demo
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
只需将其替换为mysqli_fetch_array或mysqli_result::fetch_array :) while($row = $result->fetch_array()) { echo $row['FirstName'] . " " . $row['LastName']; echo "
"; } 几乎所有的mysql_*函数都有相应的mysqli_*函数.. just replace it with mysqli_fetch_array or mysqli_resu ... -
优化的sql查询删除行(Optimized sql query to delete rows)[2023-07-26]
这将有效(见http://sqlfiddle.com/#!2/161af/1 ): delete from t where not exists (select 1 from ((select A, B from t where C = 0 order by D desc l ... -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
简单地使用不等于或不等于? 您没有指定标准,但这可能会起作用: delete from YourTable where id not in (1, 2, 3, 4, 5); 如果您的标准更复杂,您可以使用or : delete from YourTable where col1 = 'Lucy' and col2 = 'Ricky' or col1 = 'Fred' and col2 = 'Irma' or col1 = 'Thurston' and ...
-
DELETE b FROM matches a, matches b WHERE a.primary_linked_id=b.secondary_linked_id AND a.secondary_linked_id=b.primary_linked_id AND a.date = b.date ??? DELETE b FROM matches a, matches b WHERE a.primary_linked_id ...
-
delete from a where id not in ( select * from ( select a.id from ab join a on (ab.a=a.id) join b on (ab.b=b.id) where a.pid=b.pid ) x ); delete from b where id not in ( select * from ( select b.id ...
-
运行后台查询后,使用VB删除行 - Excel 2010(Delete rows with VB after background query has run - Excel 2010)[2023-02-10]
编辑4/11:我猜测发生了1004错误,因为之前删除了所有“分支未打开”行。 下面更新的代码在自动过滤步骤周围包含一个if语句,现在只有在过滤器范围内找到“Branch Not Open”的至少一个匹配时才应该应用该语句。 希望这个版本有效! @SickDimension有一个很好的开始 - 但是既然你知道许多行将在“实时日期”列中列出“分支未打开”,你可以使用autofilter快速删除它们。 尝试使用此代码(也可以更新LR代码): Private Sub Workbook_Open() Dim LR A ... -
如果您使用游标或某种循环,那么你会是对的。 你的想法是:它将获得第一个重复的ID,删除它,当它到达另一个时,条件将不再成立。 这不正确 - 当您使用这样的地方删除时,它会标记所有需要删除的内容,并将它们全部删除,而不是一个一个地删除。 因此,重复的两个ID都将被标记为应该被删除。 如果你使用光标或循环,那就像你计划的那样。 您可以在这里看到有关删除重复项的信息 You would have been right, if you'd use a cursor, or some kind of loop. Wh ...
-
您的删除语句似乎有语法错误,请尝试更改查询 DELETE S1 FROM ... 至 DELETE FROM ... 更新: 尝试使用此声明替代您的声明: DELETE FROM StateLogs WHERE Id NOT IN (SELECT TOP (1) Id FROM StateLogs ORDER BY Modified DESC) 另外,您可能会遇到基于您提供的架构对表进行插入/更新操作的问题,因为您的主键大于最大值: http : //msdn.microsoft.com/en-us/ ...