Assembly code for simple coding/decoding of string confusion?

前端 未结 2 1494
故里飘歌
故里飘歌 2021-01-26 11:22

I am learning for my exam and I am so confused by this assembly code. It is a program in which first user enters a string, than that string gets coded and printed, than decoded

2条回答
  •  [愿得一人]
    2021-01-26 12:07

    Explained:

    INC bx   ; increment bx, skip this byte (why ?)
    MOV cl, [bx]  ; get number of characters of the string
    XOR ch, ch    ; quick way to set ch to zero, so cx == cl for the loop
    
    coding:
        INC bx    ; next address
        MOV dl, [bx]  ; get character value
        XOR dl, ah    ; decode it with XOR key in ah
        MOV [bx], dl  ; store in the same memory value
    LOOP coding       ; decrement cl and goto coding if cx > 0
    

    Format of the string seems "custom", certainly not NULL terminated but rather containing size first (is it Pascal? Ada uses this kind of system)

    • The first byte seems ignored there.
    • The second byte contains the length of the following string
    • The rest of the data is the string itself

    Note that in that case encoding and decoding are the same since XOR masking is used.

提交回复
热议问题