flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
windwakr 16 Aug 2010, 23:32
ProcessWorked and ProcessFailure need to be "call"ed, not jumped to. ExtractYear fails because you forget the "pusha".
Here's the fixed code, it outputs three "Conversion complete!"s. I kind of uglified the start with my fix, though. ![]() Code: org 100h use16 xor ax, ax call PackDate call ExtractDay cmp al, 31 je daysuccess call ProcessFailure jmp @f daysuccess: call ProcessWorked @@: call ExtractMonth cmp al, 12 je monthsuccess call ProcessFailure jmp @f monthsuccess: call ProcessWorked @@: call ExtractYear cmp al, 99 je yearsuccess call ProcessFailure jmp @f yearsuccess: call ProcessWorked @@: EndProgram: mov ah, 4ch int 21h ExtractDay: ;UnPacks the day from PackedDate and returns value into al pusha xor ax, ax mov [UnPacker], al mov ax, [PackedDate] and ax, 0000000000011111b mov [UnPacker], al popa mov al, [UnPacker] ret ExtractMonth: ;UnPacks the month from PackedDate and returns value into al pusha xor ax, ax mov [UnPacker], al mov ax, [PackedDate] ror ax, 5 and ax, 0000000000001111b mov [UnPacker], al popa mov al, [UnPacker] ret ExtractYear: ;UnPacks the year from PackedDate and returns value into al pusha xor ax, ax mov [UnPacker], al mov ax, [PackedDate] ror ax, 9 and ax, 0000000001111111b mov [UnPacker], al popa mov al, [UnPacker] ret CharStrToInt: ;SI = 5 byte string of ascii chars(30h-39h) to convert to an int ;Requires word memory slot(IntValue) to hold temporary data ;Returns int in cx pusha mov cx, 5 mov [IntValue], 0 ConvertLoop: lodsb and ax, 00001111b ;Zero out H.O. nibble of ascii char cmp cx, 5 ;If placeholder is 5 then mul value by 10,000 jne @f mov bx, 10000 mul bx @@:cmp cx, 4 ;If placeholder is 4 then mul value by 1,000 jne @f mov bx, 1000 mul bx @@:cmp cx, 3 ;If placeholder is 3 then mul value by 100 jne @f mov bx, 100 mul bx @@:cmp cx, 2 ;If placeholder is 2 then mul value by 10 jne @f mov bx, 10 mul bx @@:add [IntValue], ax ;Add converted value to IntValue dec cx cmp cx, 0 jnz ConvertLoop ;Loop until cx = 0 popa mov cx, [IntValue] ret PackDate: ;Requires word var(PackedDate) to place packed value into ;Also requires three 5 byte strings(Day/Month/Year) to pack into PackedDate ;Date is packed into 16 bits bits 15-9 for year, bits 8-5 month, bits 0-4 day pusha xor cx, cx xor ax, ax mov si, Day ;Pack Day into 16bit ax call CharStrToInt or ax, cx mov si, Month ;Pack Month into 16bit ax call CharStrToInt ror ax, 5 or ax, cx mov si, Year ;Pack Year into 16bit ax call CharStrToInt ror ax, 4 or ax, cx ror ax, 7 ;Adjust so value is in Year/Month/Day format mov [PackedDate], ax popa ret ProcessWorked: pusha mov ah, 09h mov dx, PrintSuccess int 21h popa ret ProcessFailure: pusha mov ah, 09h mov dx, PrintFailure int 21h popa ret Day db '00031' Month db '00012' Year db '00099' PackedDate dw ? UnPacker db ? CharString db '65535' IntValue dw ? PrintSuccess db 'Conversion complete!',13,10,'$' PrintFailure db 'Process Failed!!!!!',13,10','$' EDIT: Ok, technically they don't need to be "call"ed. Something like this would work: Code: call ExtractDay push @f cmp al, 31 je ProcessWorked jne ProcessFailure @@: call ExtractMonth push @f cmp al, 12 je ProcessWorked jne ProcessFailure @@: call ExtractYear push @f cmp al, 99 je ProcessWorked jne ProcessFailure @@: Yeah, that looks a lot better. |
|||
![]() |
|
Walkerboh 17 Aug 2010, 00:36
ah man, facepalm! Thanks windwakr
![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.