2014-10-21 1 views
0

나는 벽에 부딪쳤을 것으로 보이며 이것에 관해서는 어떤 예제도 찾을 수 없습니다. 아스키 문자를 숫자로 변환해야합니다. 즉, 사용자 유형이 150 + 123이므로 아스키의 첫 번째 숫자를 읽은 다음 각 숫자에서 0을 빼서 dec로 변환해야합니다. 그러나 여기에 문제가 있습니다. 사용자가 1 자리 또는 5 자리를 입력 할 수 있기 때문에 실제 숫자를 만드는 방법을 모르겠습니다. 코드에서 외국 주석을 무시하십시오. 당신은 (10)에 의해 누적를 곱해야은 숫자 8086 어셈블리에 아스키 숫자를 더할 수 없습니다

.model small 
.stack 100h 

.data 

    prompt1 db "Please enter an action: ", 10, 13, "$" 
    prompt2 db "Answer: ", 10, 13, "$" 
    newline db 10, 13, '$' 
    buffer db 255 ; Denotes the number of maximal symbols hope 
    sizeread db 0 ; It will be available on how many characters scanned 
    buffer_data db 255 dup (?) ; It will be hosted on-line scanned data to fill 255 characters $ 

.code 
start: 

    mov dx, @data ; 
    mov ds, dx ; 

print_prompt: 

    mov ah, 9  
    mov dx, offset prompt1 ; Messages placed in the DX register address 
    int 21h ; welcome petraukimą 

    ret 

input: 

    mov ah, 0Ah 
    mov dx, offset buffer 
    int 21h 

    ret 

number: 

    xor bx,bx 
    xor ax,ax 
    mov al, 10 ;set al to 0 so i can MUL 
    mov cx, 5  
    loopstart: ;start the cycle 
    cmp [buffer_data+bx], ' ' ;check if I reached a space 
    je space  ; jump to space (the space func will read the + or - sign later on) 
    mov bx, [bx+1] ; bx++ 
         ;Now i got no idea how to go about this.... 

space: 
end start 
+0

[이 질문을 참조하십시오 (http://stackoverflow.com/questions/26337518/how-can-i-make-10000-1000-100-from-10-the-easiest-way/26339409). – Jester

답변

1

주셔서 감사합니다 (16 진수 16을 곱하면, 즉 사용자의 입력을 진수로되어 가정) :

xor ax, ax ; zero the accumulator 
    mov cx, 10 ; cx = 10 

input: 
    movzx bx, <next input char from left to right> 
    cmp bl, '\n' ; end of input 
    je out 
    sub bl, '0' ; convert ascii char to numeric value 
    mul cx  ; ax = ax*10, prepare for next digit (assuming result fits in 16 bits) 
    add ax, bx ; ax = ax + bx, add current digit 
    jmp input 

out: 

CX '밖으로'에 도달하기에는 숫자 값이 입력 번호.

+0

실제로'CX'를 사용할 필요가 없습니다. 여러분은'AX'를 항상 사용할 수 있습니다. 또한, 'mul 10'명령은 없기 때문에 'xor + mov'쌍 대신에'movzx'를 사용해야합니다. 사소한 주석은 유용하지 않다. 선의 더 높은 의미를 보여줘야한다. 우리는'xor cx, cx'가'cx'를 0으로 알고 있지만 우리는 그것이 왜 0이고 무엇이'cx'가 사용되는지 알지 못합니다. – Jester

+0

오른쪽. 8086 어셈블리로 작업 한 이래로 ... 편집되었습니다. – smichak

관련 문제