2017-12-21 2 views
0

내 경우 0Ah 인 Al 레지스터의 값을 표시하고 싶지만 여기에 내 코드가 있지만 nothig이 발생합니다. 확실하지는 않지만 내 문제는 내가 16 진수라고 생각합니다. 당신이 잊어 버린 모든Al 레지스터에 값 표시

; You may customize this and other start-up templates; 
; The location of this template is c:\emu8086\inc\0_com_template.txt 

org 100h 


.data segment 

Array DB 0h,0h,0h,0h,0h 
x db 0h 
result db ? 

.code segment 

mov si,0 

loop1: 
     ;these 5 lines allows me to take 
     ;input and let it be shown on the screen 

     mov ah,08h 
     int 21h 
     mov ah,02h 
     mov dl,al 
     int 21h 

     ;those 3 lines allows me 
     ;to start my code when 
     ;enter button is pressed 

     mov bl,0Dh 
     cmp bl,dl 
     JZ start 

     ;those 4 lines allow me 
     ;to enter 4 chars and 
     ;fill an array with them 
     ;to use them later 

     mov array[si],dl 
     inc si 
     cmp si,5 
     jne loop1 


start: 

     ;putting each element in the 
     ;array in a register to be 
     ;able to deal with it 

     mov si,0 
     mov al,array[si] 
     mov bl,array[si+1] 
     mov cl,array[si+2] 
     mov dl,array[si+3] 

     ;subtracting 30h from each 
     ;number to turn it to its 
     ;decimal form to deal with 
     ;it as normal number 

     sub al,30h 
     sub bl,30h 
     sub cl,30h 
     sub dl,30h 

     ;adding all numbers in 
     ;variable called result 

     add al,cl 
     add al,bl 
     add al,dl 

     ;printing 

     mov ah,02h 
     mov dl,al 
     int 21h 
     ret 
+0

이미지에 코드를 텍스트, 감사 인사에 게시하십시오. – sam

+0

done, thanks @sam –

+0

코드에 근본적인 문제가있는 것 같습니다. COM 또는 EXE 모델입니까? COM 인 경우 처음에는'.data '를 가질 수 없으며 코드로 실행됩니다 (첫 번째 명령은 코드에 대한 데이터 위에'jmp ... '가 있더라도'org 100h' 다음에 와야합니다). 그것이 EXE라면, 당신은'org 100h'을 가질 수 없으며'mov array [si], dl'처럼 사용하기 전에'ds'를 설정해야합니다 ... 나는 그들을 무시하고 다시 읽으려고 노력할 것입니다 귀하의 실제 문제입니다,하지만 당신은 몇 가지 더 많은 자습서를 시도하고 모든 것을 다시 읽고 올바른 예제를 몇 번 더 작동하는지 확인해야합니다 ... – Ped7g

답변

0

첫째 :하지만 레지스터에 난 단지 그래서 여기

예를

에 대한 문자열로 헥사 번호를 변환하는 방법은 내가 사용하는 코드가있을 것입니다 char 또는 문자열을 인쇄 할 수 있습니다 계산에 배열의 마지막 요소를 포함시킵니다.

코드는 계산에 배열의 마지막 요소를 포함합니다 :

mov bh, array[si+4] ; store the last element in BH register 

것은 당신의 컨텐츠를 변환하는이 줄을 추가

당신이 레지스터의 요소를 가하고 있습니다이 줄을 추가 소수점 이하 레지스터 :

sub bh, 30h    ; convert it to decimal 

이 줄을 추가하면 모든 레지스터의 내용을 추가 :

add al, bh    ; add contents of AL with contents of BL 

코드하는 것은 소수의 합계를 인쇄하려면 :

mov ah, 0  ; clear AH because DIV instruction takes AX for division 
    mov cl, 10 ; store the divisor in CL 
    div cl  ; AX/CL remainder will be in AH & quotient in AL 

    mov bx, ax ; move AX value to BX because later instruction are going to overwrite value of AH 

    mov ah,02h  ; print quoteint 
    mov dl,bl  
    add dl,30h  
    int 21h 

    mov ah,02h  ; print remainder 
    mov dl,bh 
    add dl,30h 
    int 21h 

귀하의 경우 이후의 모든 5 원소의 첨가 한 후 가장 많은 2 자리 숫자가 될 것입니다 (9 + 9 + 9 + 9 + 9 = 45) 우리는 한 번만 나누어야합니다. 먼저 몫을 인쇄 한 다음 나머지를 인쇄하십시오. 합계에 두 자리 이상 (예 : 123)이 포함 된 경우 동일한 프로세스를 연속적으로 반복하고 나머지가 스택에 저장 될 때까지 몫이 0이 될 때까지 스택에 저장합니다. 그런 다음 필요한 ASCII 변환을 수행 한 후 스택의 숫자를 & 표시 할 수 있습니다.