There is a program, I enter a character from the keyboard, then I get its binary code (translation of the ASII character code into binary format), then the number of single bits is counted in the number and is written to the counter variable, then I need to continue entering the next character and also do the same as with the first one (output its binary code and count the number of single bits in it).

With the first character, the program works without problems, and then I don’t display the correct number in binary format, counting single bits also does not work. I suspect that the problem is that I go to the beginning of the program (using a label) and something It remains from the previous execution, I tried to reset the registers, it still does not work.

How to go to the beginning of the program, so that it works with the new symbol? Ie, how to return all registers and variables, except the counter, to the initial position?

.8086 .model small .stack 200h DATA SEGMENT counter dw 0 STR1 DB "BINARY NUMBER IS : $" STR2 DB "DECIMAL NUMBER IS : $" BSTR DB 20 DUP("$") RSTR DB 20 DUP("$") NEWLINE DB 13,10,"$" CNT DB 0 N DB 2 H DB 16 D DB 10H NUM DB ? SNUM DB ? HNUM DB 0H DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX xor ax,ax ; EchoLoop: mov HNUM,0h xor ax,ax xor al,al xor ah,ah xor bx,bx xor dx,dx ;xor cx,cx xor dh,dh xor dl,dl mov ah,1 int 21h cmp al,13 ;Если символ Enter,выходим jz EchoDone mov HNUM,al ;Перевод из 16 в нужный нам формат------------------------------ ;CONVERT HEXA TO DECIMAL MOV CX,00 MOV DX,00 L6:MOV AX,00 MOV AL,HNUM DIV D MOV HNUM,AL MOV BX,AX MOV CL,CNT MOV AX,1 L5: CMP CL,00 JE L7 MUL H SUB CL,1 JMP L5 L7: MUL BH ADD DX,AX ADD CNT,1 CMP HNUM,0 JG L6 MOV NUM,DL ;CONVERT DECIMAL TO BINARY LEA SI,BSTR LEA DI,RSTR L1: MOV AX,00 MOV AL,NUM DIV N ADD AH,30H MOV BYTE PTR[SI],AH INC SI MOV NUM,AL CMP AL,0 JG L1 DEC SI L2:MOV BL,BYTE PTR[SI] MOV BYTE PTR[DI],BL DEC SI INC DI CMP SI,0 JNE L2 ;Перевод из 16 в нужный нам формат------------------------------ ;MOV AH,09H ;LEA DX,STR1 ;INT 21H MOV AH,09H LEA DX,RSTR INT 21H xor si,si xor bx,bx mov cx,20 ;Подсчет единичных бит cycle: inc si cmp RSTR[si-1],'1' jz metka2 loop cycle jmp EchoLoop ;Переход на начало MOV AH,4CH INT 21H metka2: inc counter ;schetchik edinichnuh bit loop cycle EchoDone: mov ah,4ch int 21h CODE ENDS END START 

In the picture, the result of the program: I enter the character a, I get its binary code, I enter the character b, it displays the garbage value.

Work result

On the 2 picture: I enter the symbol with, I get its binary code, I enter the symbol e, again I take out the garbage.

Result2

  • At least metka2 raise above. If the loop does not work out on it, the program will end immediately. Is this what is intended? - Mike
  • And by the way, the bits could be considered simultaneously with the preparation in binary form - it is somehow more practical - Mike
  • Yes, that’s what I’m supposed to do, I don’t know asm well, I’m writing as much as I can - andybelous2
  • But as soon as you finish counting the bits of the loop, the cycle which after metla2 does not go off into the loop and the command following it is executed - exit from the program - Mike
  • it goes on a cycle, I clearly see it in the debugger - andybelous2

0