汇编语言融合 [英] Assembly Language Fusing

查看:94
本文介绍了汇编语言融合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试融合一个已接受的4位数字,到目前为止,我已经完成了2位数的数字并且混淆了4位数。请帮助



这里我的代码:

  mov   01  
int 21h
sub al 30h
mov bh al

mov 01
int 21h
sub al 30h
mov bl al

打电话 fuseIt





 fuseIt PROC NEAR 
mov al bh
mov 0
mov bl 10
mul bl
add al bl
RET
fuseIt ENDP

解决方案

您需要创建一个循环并每次保存中间值。我的汇编程序非常生疏(所以可能有一些明显的错误),但我会想到:



总计: dw   0  ;  归零词 

xor ax ax
移动总计, ax ; 将总数设为零
mov cx 4 ; 重复4次
循环:
mov ax ,总计; 得到总数
mov bx 10
mul bx ; 乘以10
mov total, ax ; save new total
mov < span class =code-keyword> ah , 01
int < span class =code-digit> 21h ; 获取下一个字符
sub al 30h ; 使其成为一个数字。 NB需要检查0到9的范围。
xor ,< span class =code-keyword>啊 ; 使其成为16位
添加总计, ax ; 将其添加到总计
dec cx ; 递减计数器
jg loop ; 重复4次


I am trying to fuse an accepted 4-digit number, so far I have done the 2-digit number and got confuse fusing a 4-digit. Please help

Here my code:

mov ah,01
    int 21h
    sub al,30h
    mov bh,al

    mov ah,01
    int 21h
    sub al,30h
    mov bl,al

    call fuseIt



fuseIt PROC NEAR
    mov al,bh
    mov ah,0
    mov bl,10
    mul bl
    add al,bl
    RET
fuseIt ENDP

解决方案

You need to create a loop and save the intermediate value each time. My assembler is extremely rusty (so there are probably some obvious mistakes) but I would think something like:

total: dw 0 ; a zeroised word

    xor ax,ax
    move total,ax     ; set total to zero
    mov cx,4          ; repeat 4 times
loop:
    mov ax,total      ; get the total
    mov bx,10       
    mul bx            ; multiply by 10
    mov total,ax      ; save new total
    mov ah,01
    int 21h           ; get next character
    sub al,30h        ; make it a digit. NB need to check in range 0 to 9.
    xor ah,ah         ; make it 16 bits
    add total,ax      ; add it to the total
    dec cx            ; decrement the counter
    jg  loop          ; repeat 4 times


这篇关于汇编语言融合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆