assembly - Asm ascii to binary conversion -
im trying convert ascii input binary code in variable. program working while number of inputed char even. don't know why when odd i've got wrong result. if number of input odd i'm trying convert 8 bit binary if got 1 00000001 , put first take 2 ascii chars low , hight 4 bits. can ?
sysexit = 1 sysread = 3 syswrite = 4 stdout = 1 stdin = 0 exit_success = 0 size = 500 .align 32 .bss .lcomm bufor, size .lcomm bufor2, size .text .global _start ; _start: mov $sysread, %eax mov $stdin, %ebx mov $bufor, %ecx mov $size, %edx int $0x80 sub $1, %eax #od liczby znaków odejmujemy znak entera mov %eax, %edi #przeniesienie liczby wczytanych znaków z eax mov $0,%dx # reszta z dzielenia mov $2,%cx #dzielnik div %cx # ax:=dx:ax / cx mov $0, %esi mov $0, %ecx mov $0, %ebp petla: mov bufor(,%ecx,1),%al inc %esi cmp $'a',%al jge male cmp $'a',%al jge duze cmp $'0',%al jge liczby next: cmp $1, %dx je niep mov %al,%bl shl $4, %ebx inc %ecx cmp %edi,%ecx je koniec jmp petla next2: or %al,%bl mov %bl, bufor2(,%ebp,1) inc %ebp inc %ecx cmp %edi,%ecx je koniec mov $0,%esi jmp petla male: sub $'a', %al add $10, %al cmp $1,%esi; je next jmp next2 duze: sub $'a', %al add $10, %al cmp $1,%esi; je next jmp next2 liczby: sub $'0', %al cmp $1,%esi; je next jmp next2 niep: mov %al, bufor2(,%ebp,1) inc %ebp cmp %edi,%ecx je koniec inc %ecx mov $0,%esi mov $0,%dx jmp petla koniec: movl $sysexit, %eax; #wyjscie z programu movl $exit_success, %ebx int $0x80
Comments
Post a Comment