Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include C:/FILES/LAB4M.inc
- assume cs: code, ds: data
- data segment
- strings_max_length equ 102
- dummy db 0Dh, 0Ah, '$'
- description_string db "PROGRAM IMPLEMENTING LONG OPERATIONS$"
- input_lhs_string db "INPUT LHS:>$"
- input_rhs_string db "INPUT RHS:>$"
- multiplication_output_string db "LHS*RHS:>$"
- sum_output_string db "LHS+RHS:>$"
- sub_output_string db "LHS-RHS:>$"
- lhs db strings_max_length, 0, strings_max_length - 2 dup ('$')
- rhs db strings_max_length, 0, strings_max_length - 2 dup ('$')
- result db strings_max_length, 0, strings_max_length - 2 dup ('$')
- buffer1 db strings_max_length, 0, strings_max_length - 2 dup ('$')
- buffer2 db strings_max_length, 0, strings_max_length - 2 dup ('$')
- buffer3 db strings_max_length, 0, strings_max_length - 2 dup ('$')
- buffer4 db strings_max_length, 0, strings_max_length - 2 dup ('$')
- carry_buffer db 0
- strerr db "error$"
- is_hex_algebra db 0
- data ends
- code segment
- .386
- ; newline()
- newline proc
- push dx
- push ax
- mov dx, offset dummy
- mov ax, 0900h
- int 21h
- pop ax
- pop dx
- ret
- endp
- ; ~ is_zero(char* dst)
- ; dst == "0" ? ax = 1: ax = 0
- is_zero proc
- push bp
- push si
- mov bp, sp
- mov ax, 0
- mov si, [bp+6]
- cmp byte ptr [si+1], 1
- jne is_zero_return
- cmp byte ptr [si+2], 48
- jne is_zero_return
- mov ax, 1
- is_zero_return:
- pop si
- pop bp
- ret 2
- endp
- ; convert_char_to_int(char ch)
- ; ch >= A && ch <= 0 ? dx = ch-'A':dx = ch-'0'
- convert_char_to_int proc
- push bp
- mov bp, sp
- mov dx, [bp+4]
- cmp dx, 65
- jge convert_char_to_int_hex ; dx >= 'A'
- convert_char_to_int_dec:
- sub dx, 48 ; dx -= '0'
- jmp convert_char_to_int_return
- convert_char_to_int_hex:
- sub dx, 65 ; dx -= 'A'
- add dx, 10
- convert_char_to_int_return:
- pop bp
- ret 2
- endp
- ; convert_int_to_char(char value)
- ; value >= 10? dx = (value - 10)+'A' : dx = value + '0'
- convert_int_to_char proc
- push bp
- mov bp, sp
- mov dx, [bp+4]
- cmp dx, 10
- jge convert_int_to_char_hex
- convert_int_to_char_dec:
- add dx, 48
- jmp convert_int_to_char_return
- convert_int_to_char_hex:
- sub dx, 10
- add dx, 65
- convert_int_to_char_return:
- pop bp
- ret 2
- endp
- ; get_value_sign(char* value)
- get_value_sign proc
- push bp
- mov bp, sp
- push si
- mov si, [bp+4]
- mov dx, 0
- cmp byte ptr[si+2], 45
- jne get_value_sign_return
- inc dx
- get_value_sign_return:
- pop si
- pop bp
- ret 2
- endp
- ;str_push_begin(char* dst, char value)
- ;! value == 00**h
- str_push_begin proc
- push bp
- mov bp, sp
- push si
- push di
- push ax
- push cx
- push bx
- mov si, [bp+6]
- mov ax, [bp+4]
- mov cl, byte ptr[si+1]
- add si, cx
- inc cx
- add si, 2
- mov di, si
- inc di
- ;si = str.end(), di = str.end()+1, cx = len(str)+1
- str_push_begin_shift_loop:
- mov bl, byte ptr [si]
- mov byte ptr [di], bl
- dec di
- dec si
- loop str_push_begin_shift_loop
- mov si, [bp+6]
- mov byte ptr[si+2],al
- inc byte ptr[si+1]
- pop bx
- pop cx
- pop ax
- pop di
- pop si
- pop bp
- ret 4
- endp
- ; str_del_begin(char* dst)
- str_del_begin proc
- push bp
- mov bp, sp
- push si
- push di
- push cx
- push ax
- mov si, [bp+4]
- mov cl, byte ptr[si+1]
- cmp cl, 0
- je str_del_begin_return
- add si, 2
- mov di, si
- inc di
- str_del_begin_loop:
- mov al, byte ptr[di]
- mov byte ptr[si], al
- inc si
- inc di
- loop str_del_begin_loop
- mov si, [bp+4]
- dec byte ptr[si+1]
- str_del_begin_return:
- pop ax
- pop cx
- pop di
- pop si
- pop bp
- ret 2
- endp
- ; str_clear_leading_zeroes(char* dst)
- str_clear_leading_zeroes proc
- push bp
- mov bp, sp
- push si
- mov si, [bp+4]
- cmp byte ptr[si+2], 48
- jne str_clear_leading_zeroes_return
- str_clear_leading_zeroes_loop:
- push si
- call str_del_begin
- cmp byte ptr[si+2], 48
- je str_clear_leading_zeroes_loop
- str_clear_leading_zeroes_return:
- pop si
- pop bp
- ret 2
- endp
- ;strcpy(char* dst, char* src)
- strcpy proc
- push bp
- mov bp, sp
- push di
- push si
- push cx
- push ax
- mov di, [bp+6]
- mov si, [bp+4]
- mov cl, byte ptr[si+1]
- mov byte ptr[di+1], cl
- add si, 2
- add di, 2
- inc cx
- strcpy_loop:
- mov al, byte ptr[si]
- mov byte ptr[di], al
- inc si
- inc di
- loop strcpy_loop
- pop ax
- pop cx
- pop si
- pop di
- pop bp
- ret 4
- endp
- ; strclear(char* dst)
- strclear proc
- push bp
- mov bp, sp
- push si
- push cx
- mov si, [bp+4]
- mov cl, byte ptr[si+1]
- mov byte ptr[si+1], 0
- add si, 2
- cmp cl, 0
- je strclear_return
- strclear_loop:
- mov byte ptr[si], 36
- inc si
- loop strclear_loop
- strclear_return:
- pop cx
- pop si
- pop bp
- ret 2
- endp
- ;strfill_with_zeroes(char* dst, char num)
- strfill_with_zeroes proc
- push bp
- mov bp, sp
- push si
- push cx
- push ax
- mov si, [bp+6]
- mov cx, [bp+4]
- mov ax, 48
- cmp cx, 0
- je strfill_with_zeroes_return
- strfill_with_zeroes_loop:
- push si
- push ax
- call str_push_begin
- loop strfill_with_zeroes_loop
- strfill_with_zeroes_return:
- pop ax
- pop cx
- pop si
- pop bp
- ret 4
- endp
- ; write_result_of_operation(char* dst, char value, char* carry_buffer)
- ; ! value == 00**h !
- write_result_of_operation proc
- push bp
- mov bp, sp
- push si
- push di
- push ax
- push bx
- mov si, [bp+8]
- mov ax, [bp+6]
- mov di, [bp+4]
- cmp is_hex_algebra, 1
- je write_result_of_operation_hex
- write_result_of_operation_dec:
- mov bl, 10
- jmp write_result_of_operation_write
- write_result_of_operation_hex:
- mov bl, 16
- write_result_of_operation_write:
- div bl ; al /= bl, ah = al % bl
- mov byte ptr [di], al
- mov al, ah
- mov ah, 0
- push ax
- call convert_int_to_char
- push si
- push dx
- call str_push_begin
- write_result_of_operation_return:
- pop bx
- pop ax
- pop di
- pop si
- pop bp
- ret 6
- endp
- ;long_sum(char* dst, char* lhs, char* rhs)
- long_sum proc
- push bp
- mov bp, sp
- push si
- push di
- push cx
- push bx
- push dx
- push ax
- mov si, [bp+6] ;lhs value
- mov di, [bp+4] ;rhs value
- ; handling negative values
- push 0000h ; set (local) set_minus_sign = false
- push si
- call get_value_sign
- mov al, dl
- push di
- call get_value_sign
- mov bl, dl
- cmp al, 1
- je long_sum_handling_negative_values_lhs_negative ; if lhs_sign = '-'
- ;if lhs_sign = '+'
- cmp bl, 1
- jne long_sum_handling_negative_values_end; if rhs_sign = '+'
- ;if lhs_sign = '+' && rhs_sign = '-'
- push offset buffer4
- push word ptr[bp+4]
- call strcpy
- push offset buffer4
- call str_del_begin
- mov di, offset buffer4
- mov word ptr[bp+4], di
- push word ptr[bp+8]
- push word ptr[bp+6]
- push word ptr[bp+4]
- call long_sub
- pop ax ; get (local) set_minus_sign
- jmp long_sum_return
- long_sum_handling_negative_values_lhs_negative:
- ;if lhs_sign = '-'
- push offset buffer3
- push word ptr[bp+6]
- call strcpy
- push offset buffer3
- call str_del_begin
- mov si, offset buffer3
- mov word ptr[bp+6], si
- cmp bl, 1
- je long_sum_handling_negative_values_lhs_negative_rhs_negative
- ; if lhs_sign = '-' && rhs_sign = '+'
- push word ptr[bp+8]
- push word ptr[bp+4]
- push word ptr[bp+6]
- call long_sub
- pop ax ; get (local) set_minus_sign
- jmp long_sum_return
- long_sum_handling_negative_values_lhs_negative_rhs_negative:
- ; if lhs_sign = '-' && rhs_sign = '-'
- push offset buffer4
- push word ptr[bp+4]
- call strcpy
- push offset buffer4
- call str_del_begin
- mov di, offset buffer4
- mov word ptr[bp+4], di
- pop ax
- push 0001h ; set (local) set_minus_sign = true
- long_sum_handling_negative_values_end:
- mov cl, byte ptr[si+1]
- cmp cl , byte ptr[di+1]
- jl long_sum_start
- long_sum_swap_pointers:
- mov si, [bp+4]
- mov di, [bp+6]
- xor cx,cx
- long_sum_start:
- ;saving di
- push di
- ;di = biggest_string.end()-1, si = smallest_string.end()-1
- mov cl, byte ptr[di+1]
- add di, cx
- inc di
- mov cl, byte ptr[si+1]
- add si, cx
- inc si
- long_sum_small_loop:
- ; al = int(*si)
- mov al, byte ptr[si]
- push ax
- call convert_char_to_int
- mov ax, dx
- ; bl = int(*di)
- mov bl, byte ptr[di]
- push bx
- call convert_char_to_int
- mov bx, dx
- ;al = al + bl + carry_buffer
- add al, bl
- add al, carry_buffer
- ;res.push_begin(al)
- push word ptr [bp+8]
- push ax
- push offset carry_buffer
- call write_result_of_operation
- dec si
- dec di
- loop long_sum_small_loop
- ;restoring di in si
- pop si
- ; cx = biggest_string.size()-(biggest_string.end()-1-di)
- mov cl, byte ptr[si+1]
- mov ax, si
- add ax, cx
- inc ax
- sub ax, di
- sub cl, al
- cmp cx, 0
- je long_sum_write_carry_buffer_end
- long_sum_end_loop:
- xor ax,ax
- mov bl, byte ptr[di]
- push bx
- call convert_char_to_int
- mov bx, dx
- ;al = al + bl + carry_buffer
- add al, bl
- add al, carry_buffer
- ;res.push_begin(al)
- push word ptr [bp+8]
- push ax
- push offset carry_buffer
- call write_result_of_operation
- dec di
- loop long_sum_end_loop
- pop ax ; get (local)set_minus_sign
- cmp al, 1
- jne long_sum_return
- push word ptr[bp+8]
- push 0045
- call str_push_begin
- jmp long_sum_return
- long_sum_write_carry_buffer_end:
- cmp carry_buffer, 0
- je long_sum_writting_minus_sign_begin
- push word ptr [bp+8]
- mov al, carry_buffer
- push ax
- push offset carry_buffer
- call write_result_of_operation
- long_sum_writting_minus_sign_begin:
- ; writting minus sign if needed
- pop ax ; get (local)set_minus_sign
- cmp al, 1
- jne long_sum_return
- push word ptr[bp+8]
- push 0045
- call str_push_begin
- long_sum_return:
- mov carry_buffer, 0
- pop ax
- pop dx
- pop bx
- pop cx
- pop di
- pop si
- pop bp
- ret 6
- endp
- ;byte long_cmp(byte* lhs, byte* rhs)
- ; dx = 0 - lhs < rhs
- ; dx = 1 - lhs = rhs
- ; dx = 2 - lhs > rhs
- long_cmp proc
- push bp
- mov bp, sp
- push si
- push di
- push cx
- push ax
- push bx
- mov si, [bp+6]
- mov di, [bp+4]
- mov cl, byte ptr[si+1]
- cmp cl, byte ptr[di+1]
- jl long_cmp_return_0
- jg long_cmp_return_2
- add si, 2
- add di, 2
- long_cmp_loop:
- mov al, byte ptr [si]
- push ax
- call convert_char_to_int
- mov ax, dx
- mov bl, byte ptr [di]
- push bx
- call convert_char_to_int
- mov bx, dx
- cmp al, bl
- jg long_cmp_return_2
- jl long_cmp_return_0
- inc si
- inc di
- loop long_cmp_loop
- mov dx, 1
- jmp long_cmp_return
- long_cmp_return_0:
- mov dx, 0
- jmp long_cmp_return
- long_cmp_return_2:
- mov dx, 2
- long_cmp_return:
- pop bx
- pop ax
- pop cx
- pop di
- pop si
- pop bp
- ret 4
- endp
- ; long_sub(char* res, char* lhs, char* rhs) ~ res = lhs - rhs
- long_sub proc
- push bp
- mov bp, sp
- push si
- push di
- push cx
- push ax
- push bx
- mov si, [bp+6] ;lhs string
- mov di, [bp+4] ;rhs string
- ;handling negative values
- push word ptr[bp+6]
- call get_value_sign
- mov al, dl
- push word ptr[bp+4]
- call get_value_sign
- mov bl, dl
- cmp al, 1
- je long_sub_handling_negative_values_lhs_negative ; if lhs_sign = '-'
- ;if lhs_sign = '+'
- cmp bl, 1
- jne long_sub_handling_negative_values_end ; if lhs_sign = '+' && rhs_sign = '+'
- ;if lhs_sign = '+' && rhs_sign = '-'
- push offset buffer4
- push word ptr[bp+4]
- call strcpy
- push offset buffer4
- call str_del_begin
- push word ptr[bp+8]
- push word ptr[bp+6]
- push offset buffer4
- call long_sum
- jmp long_sub_return
- long_sub_handling_negative_values_lhs_negative:
- ; if lhs_sign = '-'
- cmp bl, 1
- je long_sub_handling_negative_values_lhs_negative_rhs_negative ; if rhs_sign = '-'
- ;if lhs_sign = '-' && rhs_sign = '+'
- ; adding '-' to copied rhs and call long_sum
- push offset buffer4
- push word ptr[bp+4]
- call strcpy
- push offset buffer4
- push 0045 ; '-'
- call str_push_begin
- push word ptr[bp+8]
- push word ptr[bp+6]
- push offset buffer4
- call long_sum
- jmp long_sub_return
- long_sub_handling_negative_values_lhs_negative_rhs_negative:
- ; if lhs_sign = '-' && rhs_sign = '-'
- push offset buffer3
- push word ptr[bp+6]
- call strcpy
- push offset buffer3
- call str_del_begin
- mov si, di
- mov di, offset buffer3
- mov word ptr[bp+4], di
- push offset buffer4
- push si
- call strcpy
- push offset buffer4
- call str_del_begin
- mov si, offset buffer4
- mov word ptr[bp+6], si
- long_sub_handling_negative_values_end:
- push 0000h ; (local) set_minus_sign = false
- push si
- push di
- call long_cmp
- cmp dx, 1
- je long_sub_return_0
- jg long_sub_start
- pop si; getting (local) set_minus_sign
- push 0001h ; (local) set_minus_sign = true
- ; swap pointers
- mov si, [bp+4]
- mov di, [bp+6]
- long_sub_start:
- push si ; (local) saving biggest value pointer
- ; si = biggest_value.end()-1, di = smallest_value.end()-1
- mov cl, byte ptr[si+1]
- add si, cx
- inc si
- mov cl, byte ptr[di+1]
- add di, cx
- inc di
- long_sub_small_loop:
- ; al = int(*si)
- mov al, byte ptr[si]
- push ax
- call convert_char_to_int
- mov ax, dx
- ; bl = int(*di)
- mov bl, byte ptr[di]
- push bx
- call convert_char_to_int
- mov bx, dx
- add bl, carry_buffer
- cmp al, bl
- jl long_sub_small_loop_carry
- long_sub_small_loop_not_carry:
- mov carry_buffer, 0
- jmp long_sub_small_loop_continue
- long_sub_small_loop_carry:
- mov carry_buffer, 1
- cmp is_hex_algebra, 1
- je long_sub_small_loop_carry_hex
- long_sub_small_loop_carry_dec:
- add al,10
- jmp long_sub_small_loop_continue
- long_sub_small_loop_carry_hex:
- add al,0fh
- long_sub_small_loop_continue:
- sub al, bl
- push word ptr[bp+8]
- push ax
- push offset buffer1 + 1
- call write_result_of_operation
- dec si
- dec di
- loop long_sub_small_loop
- ; di = &biggest_value
- pop di
- ; cx = biggest_string.size()-(biggest_string.end()-1-si)
- mov cl, byte ptr[di+1]
- mov ax, di
- add ax, cx
- inc ax
- sub ax, si
- sub cl, al
- cmp cx, 0
- je long_sub_write_sign
- long_sub_end_loop:
- ; al = int(*si)
- mov al, byte ptr[si]
- push ax
- call convert_char_to_int
- mov ax, dx
- ; bl = 0
- xor bx, bx
- add bl, carry_buffer
- cmp al, bl
- jl long_sub_end_loop_carry
- long_sub_end_loop_not_carry:
- mov carry_buffer, 0
- jmp long_sub_end_loop_continue
- long_sub_end_loop_carry:
- mov carry_buffer, 1
- cmp is_hex_algebra, 1
- je long_sub_end_loop_carry_hex
- long_sub_end_loop_carry_dec:
- add al,10
- jmp long_sub_end_loop_continue
- long_sub_end_loop_carry_hex:
- add al,0fh
- long_sub_end_loop_continue:
- sub al, bl
- push word ptr[bp+8]
- push ax
- push offset buffer1 + 1
- call write_result_of_operation
- dec si
- loop long_sub_end_loop
- long_sub_write_sign:
- ; restoring (local) set_minus_sign in dx
- push word ptr [bp+8]
- call str_clear_leading_zeroes
- pop dx
- cmp dx, 1
- jne long_sub_return
- push word ptr[bp+8]
- mov ax, 45 ; ax = '-'
- push ax
- call str_push_begin
- jmp long_sub_return
- long_sub_return_0:
- ; res = "0"
- pop dx
- mov si, [bp+8]
- mov byte ptr[si+1],1
- mov byte ptr[si+2],48
- long_sub_return:
- mov carry_buffer, 0
- mov byte ptr[offset buffer1 + 1], 0
- pop bx
- pop ax
- pop cx
- pop di
- pop si
- pop bp
- ret 6
- endp
- ; ~ long_multiply(char* res, char* lhs, char* rhs)
- long_multiply proc
- push bp
- mov bp, sp
- push ax
- push bx
- push cx
- push dx
- push si
- push di
- ;setting result to 0
- mov si, [bp+8]
- mov byte ptr [si+1], 1
- mov byte ptr [si+2], 48
- ;loading lhs and rhs
- mov di, [bp+4]
- mov si, [bp+6]
- ;check does first argument eq 0
- push si
- call is_zero
- cmp ax, 1
- je long_multiply_return
- ;check does second argument eq 0
- push di
- call is_zero
- cmp ax, 1
- je long_multiply_return
- ;handling negative values
- push 0000h ; (local)set_minus_sign = false
- push si
- call get_value_sign
- mov al, dl
- push di
- call get_value_sign
- mov bl, dl
- cmp al, 1
- je long_multiply_lhs_negative ; if lhs_sign = '-'
- cmp bl, 1
- jne long_multiply_start ;if lhs_sign = '+' && rhs_sign = '+'
- ;if lhs_sign = '+' && rhs_sign = '-'
- ;copying rhs, remember to put '-', deleting '-' in copy
- pop ax ; get (local)set_minus_sign
- push 0001; set (local)set_minus_sign = true
- push offset buffer3
- push word ptr[bp+4]
- call strcpy
- push offset buffer3
- call str_del_begin
- mov di, offset buffer3
- mov word ptr[bp+4], di
- jmp long_multiply_start
- long_multiply_lhs_negative:
- ;if lhs_sign = '-'
- ;copying lhs, remember to put '-', deleting '-' in copy
- pop ax ; get (local)set_minus_sign
- push 0001h ; set (local)set_minus_sign = true
- push offset buffer3
- push word ptr[bp+6]
- call strcpy
- push offset buffer3
- call str_del_begin
- mov si, offset buffer3
- mov word ptr[bp+6], si
- cmp bl, 1
- jne long_multiply_start ; if lhs_sign = '-' && rhs_sign = '+'
- ;if lhs_sign = '-' && rhs_sign = '-'
- ;copying rhs, remember to put '+', deleting '-' in copy
- pop ax ; get (local)set_minus_sign
- push 0000; set (local)set_minus_sign = false
- push offset buffer4
- push word ptr[bp+4]
- call strcpy
- push offset buffer4
- call str_del_begin
- mov di, offset buffer4
- mov word ptr[bp+4], di
- long_multiply_start:
- ;moving di to end of rhs string and setting iterations
- mov cl, byte ptr[di+1]
- add di, cx
- inc di
- loop_over_rhs_value:
- ;filling buffer1 with 0
- push ax
- push di
- mov di, [bp+4]
- mov al, byte ptr[di+1]
- sub al, cl
- push offset buffer1
- push ax
- call strfill_with_zeroes
- pop di
- pop ax
- ;moving si to end of lhs string and setting iterations for inner loop
- push cx
- mov si, [bp+6]
- mov cl, byte ptr[si+1]
- add si, cx
- inc si
- mov carry_buffer, 0
- loop_over_lhs_value:
- ; converting lhs char to integer
- mov al, [si]
- push ax
- call convert_char_to_int
- mov ax, dx
- ; converting rhs char to integer
- mov bl, [di]
- push bx
- call convert_char_to_int
- mov bx, dx
- ;multiply digits and write to buffer1
- mul bl ; al = al * bl
- add al, carry_buffer ; al += carry_buffer
- push offset buffer1
- push ax
- push offset carry_buffer
- call write_result_of_operation
- dec si ;iterate over lhs
- loop loop_over_lhs_value
- ;write carry buffer if it != 0
- cmp carry_buffer, 0
- je writting_carry_buffer_end
- writting_carry_buffer_start:
- push offset buffer1
- mov al, carry_buffer
- push ax
- push offset carry_buffer
- call write_result_of_operation
- writting_carry_buffer_end:
- pop cx ;return outter loop iterations
- ; long_sum(...) buffer2 = res + buffer1
- push offset buffer2
- push word ptr [bp+8]
- push offset buffer1
- call long_sum
- ; strcpy(...) res = buffer2
- push word ptr [bp+8]
- push offset buffer2
- call strcpy
- ; strclear(...) buffer2 = ""
- push offset buffer2
- call strclear
- ; strclear(...) buffer = ""
- push offset buffer1
- call strclear
- dec di ;iterate over rhs
- loop loop_over_rhs_value
- pop ax ;get (local)set_minus_sign
- cmp al, 0
- je long_multiply_return ;if set_minus_sign = false
- push word ptr[bp+8]
- push 0045
- call str_push_begin
- long_multiply_return:
- mov carry_buffer, 0
- pop di
- pop si
- pop dx
- pop cx
- pop bx
- pop ax
- pop bp
- ret 6
- endp
- ; check_string_correctness(char* dst)
- check_string_correctness proc
- push bp
- mov bp, sp
- push si
- push cx
- push ax
- mov si, [bp+4]
- mov cl, byte ptr[si+1]
- add si, 2
- cmp byte ptr[si], 45
- jne check_string_correctness_loop ; *si != '-'
- inc si
- dec cx
- check_string_correctness_loop:
- mov al, byte ptr[si]
- cmp al, 65
- jl check_string_correctness_loop_cmp_0 ; al < 'A'
- cmp al, 70
- jg error ; al > 'F'
- mov is_hex_algebra, 1
- inc si
- loop check_string_correctness_loop
- cmp cx,0
- je check_string_correctness_return
- check_string_correctness_loop_cmp_0:
- cmp al, 48
- jl error ; al < '0'
- cmp al, 57
- jg error
- inc si
- loop check_string_correctness_loop
- jmp check_string_correctness_return
- error:
- println_string <offset strerr>
- mov ax, 4C00h
- int 21h
- check_string_correctness_return:
- pop ax
- pop cx
- pop si
- pop bp
- ret 2
- endp
- start:
- mov ax, data
- mov ds, ax
- xor ax, ax
- print_string <offset description_string>
- call newline
- print_string <offset input_lhs_string>
- readln_string lhs
- push offset lhs
- call check_string_correctness
- print_string <offset input_rhs_string>
- readln_string rhs
- push offset rhs
- call check_string_correctness
- ; output lhs*rhs
- push offset result
- push offset lhs
- push offset rhs
- call long_multiply
- print_string <offset multiplication_output_string>
- print_string <offset result + 2>
- call newline
- ; clear result string
- push offset result
- call strclear
- ; output lhs+rhs
- push offset result
- push offset lhs
- push offset rhs
- call long_sum
- print_string <offset sum_output_string>
- print_string <offset result + 2>
- call newline
- ; clear result string
- push offset result
- call strclear
- ; output lhs-rhs
- push offset result
- push offset lhs
- push offset rhs
- call long_sub
- print_string <offset sub_output_string>
- print_string <offset result + 2>
- mov ax, 4C00h
- int 21h
- code ends
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement